5

Bu snackbar görünür olduğunda yukarı doğru "NEXT" düğmesine basmak için benim girişimidir. textviewRelativeLayout'un arkasına ve arkasına itilmiş gibi görünür ve snackbar kaybolduğunda yeniden görünür. Bunun yerine, istediğim textview'un (snackbar'un üstündedir) görünmesi ve snackbar kaybolduğunda geri gelmesidir. Ayrıca Bunu göstermek için küçük bir github repo oluşturduk:Snackbar görüntülendiğinde mevcut görünümü nasıl yukarı ittiririm? Gördüğünüz gibi planlandığı gibi</p> <p><img src="https://i.stack.imgur.com/Map0v.gif" height="400"></p> <p>, çalışmıyor:

İşte

https://github.com/Winghin2517/TestFabMotion

Ben kendisini gizlemek için "SONRAKİ" için kullanmak CoordinatorLayout.Behavior olduğunu. o kadar baskı yapılınca snackbar göründüğünde Davranış FAB davranıştan alınır:

<?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> 

Ben de bu xml kullanarak denedim:

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; 
    } 
} 

Ben bunun bu xml kullanarak denedi

<?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> 

Sadece çalışmıyor gibi görünüyor. Bunu nasıl çalıştırabileceğimi bilen var mı? Bunda ne

cevap

1

çeşitli çözümler test ettikten sonra, ben bir xml rastladım işe yarayan düzen.

aşağıda önce denenmiş ve ne olduğunu arasındaki temel fark coordinatorlayout yükseklik bunun altında görüşlerini kaplayan ancak coordinatorlayout şeffaf olduğu için, bunu görmüyorum ve ne zaman snackbar anlamına gelen "match_parent" olmasıdır

<?xml version="1.0" encoding="utf-8"?> 

    <RelativeLayout 
     android:layout_width="match_parent" 
     android:layout_height="match_parent" 
     android:background="@color/colorPrimary" 
     xmlns:android="http://schemas.android.com/apk/res/android" 
     xmlns:app="http://schemas.android.com/apk/res-auto" 
     android:layout_weight="1"> 

     <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" /> 

     <ImageButton 
      android:id="@+id/btnComments" 
      android:layout_width="48dp" 
      android:layout_height="48dp" 
      android:layout_below="@+id/click_here" 
      android:layout_centerHorizontal="true" 
      android:background="@drawable/shadow_bg" 
      android:src="@mipmap/ic_launcher" /> 

    <android.support.design.widget.CoordinatorLayout 
     android:id="@+id/coordinatorlayout" 
     android:layout_width="match_parent" 
     android:layout_height="match_parent" 
     android:layout_gravity="center_horizontal|bottom"> 

     <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" 
      android:layout_gravity="center_horizontal|bottom" 
      app:layout_behavior="fabmotiontest.com.fabtest.FloatingActionButtonBehavior" /> 

    </android.support.design.widget.CoordinatorLayout> 

</RelativeLayout> 
+0

Merhaba, simon, benim durumumda kart içeriğini aşağıya göstermek için CardView'a ayarlamam gerekiyor, ancak aperatif çubuğu kart görüntülemenin başladığını ancak sarma içeriği nedeniyle kesildiğini ancak ana sayfayla eşleşecek şekilde ayarlanmasını sağlar. tüm görüş. lütfen önermek! RL -> Cordinator -> CardView (fab özellikli) -> Relativelayout (iki görüntülü) –

0

: Kullanmak koordinatları hangi x ve y bilmiyorum

Button button = (Button)findViewById(R.id.next); 
button.setLayoutParams(new RelativeLayout.LayoutParams(
    RelativeLayout.LayoutParams.FILL_PARENT, RelativeLayout.LayoutParams, 
    myNewX, myNewY)); 

, denemek zorunda kalacak ...

+1

Bu düğme animasyon olmaz: aşağıdan yukarı iter, şimdi snackbar yukarıda textview itmek için yeterli yer olacak. Bu sadece yeniden boyutlandıracaktır. – Simon

İlgili konular