これはsnackbar
が表示されているときに上向きに「次へ」ボタンをプッシュする私の試みです:スナックバーが表示されているときに既存のビューをプッシュするにはどうすればよいですか?
あなたが見ることができるように計画されたとして、それは動作しません。 textview
が押し込まれてRelativeLayout
の後ろにあるように見え、snackbar
が消えると再び表示されます。代わりに、私が欲しいのは、textview
が押し上げられたように見えて(snackbar
を超えている)、snackbar
が消えると元に戻ります。私は自分自身を隠すために「NEXT」に使用CoordinatorLayout.Behavior
です。ここ
https://github.com/Winghin2517/TestFabMotion
:私もこれを実証するために、小さなgithubのレポを作成しました。
public class FloatingActionButtonBehavior extends CoordinatorLayout.Behavior<TextView> {
public FloatingActionButtonBehavior(Context context, AttributeSet attrs) {
}
@Override
public boolean layoutDependsOn(CoordinatorLayout parent, TextView child, View dependency) {
return dependency instanceof Snackbar.SnackbarLayout;
}
@Override
public boolean onDependentViewChanged(CoordinatorLayout parent, TextView child, View dependency) {
float translationY = Math.min(0, dependency.getTranslationY() - dependency.getHeight());
child.setTranslationY(translationY);
return true;
}
}
私はこのXMLを使用して、これを試してみました:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:orientation="vertical">
<android.support.design.widget.CoordinatorLayout
android:id="@+id/coordinatorlayout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight="0">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto">
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Click Here!"
android:textAllCaps="true"
android:textStyle="bold"
android:background="@color/colorAccent"
android:id="@+id/click_here"
android:textSize="22sp"
android:layout_marginBottom="12dp"
android:gravity="center_horizontal"
android:paddingTop="24dp"
android:paddingLeft="24dp"
android:paddingRight="24dp" />
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@+id/click_here"
android:layout_centerHorizontal="true"
android:src="@mipmap/ic_launcher"/>
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="@+id/next"
android:text="Next"
android:layout_alignParentBottom="true"
android:background="@color/colorAccent"
android:clickable="true"
android:gravity="center_horizontal"
android:padding="16dp"
android:textAllCaps="true"
android:textStyle="bold"
app:layout_behavior="fabmotiontest.com.fabtest.FloatingActionButtonBehavior" />
</RelativeLayout>
</android.support.design.widget.CoordinatorLayout>
</LinearLayout>
は、私はまた、このXMLを使用して試してみました:
をsnackbar
が表示されたら、それが押し上げますときの挙動は、FABの行動から取られます
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:orientation="vertical">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto">
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Click Here!"
android:textAllCaps="true"
android:textStyle="bold"
android:background="@color/colorAccent"
android:id="@+id/click_here"
android:textSize="22sp"
android:layout_marginBottom="12dp"
android:gravity="center_horizontal"
android:paddingTop="24dp"
android:paddingLeft="24dp"
android:paddingRight="24dp" />
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@+id/click_here"
android:layout_centerHorizontal="true"
android:src="@mipmap/ic_launcher"/>
</RelativeLayout>
<android.support.design.widget.CoordinatorLayout
android:id="@+id/coordinatorlayout"
android:layout_alignParentBottom="true"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="0">
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="@+id/next"
android:text="Next"
android:background="@color/colorAccent"
android:clickable="true"
android:gravity="center_horizontal"
android:padding="16dp"
android:textAllCaps="true"
android:textStyle="bold"
app:layout_behavior="fabmotiontest.com.fabtest.FloatingActionButtonBehavior" />
</android.support.design.widget.CoordinatorLayout>
</LinearLayout>
これは機能していないようです。誰も私がそれを働かせる方法を知っていますか?そのことについては何
こんにちは、サイモン、私の場合は、私は下にそれを示すためにcardViewにラップコンテンツを設定する必要がありますがスナックバーは、カードビューが上がるが、それはラップのコンテンツのためにカットされますが、すべてのビュー。親切にお勧め! RL - >コーディネータ - > CardView(fabプロパティ付き) - > Relativelayout(2枚の画像付き) –