mein Versuch, die „NEXT“ Taste nach oben zu drücken, wenn die snackbar
sichtbar ist:Wie schiebe ich eine vorhandene Ansicht, wenn Snackbar angezeigt wird? Dies ist
Wie Sie sehen können, ist es nicht wie geplant funktionieren. Es scheint, als ob die textview
wurde nach oben und hinter der RelativeLayout
geschoben und erscheint dann wieder, wenn die snackbar
verschwindet. Stattdessen möchte ich, dass die textview
hochgeschoben erscheint (also über der snackbar
liegt) und dann wieder herunterfährt, wenn die snackbar
verschwindet. Ich habe auch ein kleines GitHub Repo demonstrieren diese erstellt:
https://github.com/Winghin2517/TestFabMotion
Hier ist die CoordinatorLayout.Behavior
ich für den „NEXT“ verwenden, um mich zu verstecken. Das Verhalten wird von dem FAB Verhalten genommen, wenn es nach oben gedrückt wird, wenn die snackbar
erscheint:
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;
}
}
Ich habe versucht, dies dieses xml mit:
<?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>
ich auch versucht habe, mit diesem 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">
<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>
Es scheint einfach nicht zu funktionieren. Weiß jemand, wie ich es zum Laufen bringen kann?
Hallo zusammen, simon, in meinem Fall muss ich Wrap Inhalt auf cardView setzen, um es unten zu zeigen, aber wenn die Snackbar zeigt, dass cardview hochgeht, wird es wegen des Wrap Contents geschnitten, aber wenn man es auf Eltern setzt, wird es auf die Oberseite gesetzt alle anzeigen. bitte vorschlagen.! RL -> Cordinator -> CardView (mit Fab-Eigenschaft) -> Relative Layout (mit zwei Bildern) –