7

Tôi cố gắng để sử dụng futuresimple's FloatingActionButton library sử dụng một FloatingActionMenu bên trong một CoordinatorLayout vì vậy khi tôi hiển thị một Snackbar FAB sẽ di chuyển lên và không được ẩn bởi Snackbar. FloatingActionMenu hoạt động hoàn hảo mặc dù tôi đã nhận thấy thư viện của bên thứ ba không hoạt động bên trong CoordinatorLayout.Bên Thứ Ba FloatingActionButton Thư viện trong CoordinatorLayout

Khi tôi sử dụng thư viện hỗ trợ FAB từ Google, CoordinatorLayout hoạt động như mong đợi, mặc dù thư viện của FutureSimple thì không. (Nó đang bị ẩn bởi Snackbar).

Tôi làm cách nào để thư viện của bên thứ ba hoạt động với CoordinatorLayout?

fragment_comic.xml

<RelativeLayout 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content"> 
<TextView 
    android:id="@+id/title" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:gravity="center_horizontal" 
    android:paddingLeft="@dimen/activity_horizontal_margin" 
    android:paddingRight="@dimen/activity_horizontal_margin" 
    android:text="@string/default_title" 
    android:textAppearance="?android:textAppearanceLarge" 
    android:layout_centerHorizontal="true" /> 

<TextView 
    android:id="@+id/alt" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:layout_below="@+id/title" 
    android:layout_centerHorizontal="true" 
    android:layout_gravity="center_horizontal" 
    android:fadeScrollbars="false" 
    android:gravity="center" 
    android:maxLines="4" 
    android:textColor="@color/black" 
    android:paddingBottom="13dp" 
    android:paddingLeft="@dimen/activity_horizontal_margin" 
    android:paddingRight="@dimen/activity_horizontal_margin" 
    android:scrollbars="vertical" 
    android:text="@string/default_alt" 
    android:textAppearance="?android:textAppearanceMedium" /> 

<ImageView 
    android:id="@+id/imageView" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    android:layout_below="@+id/alt" 
    android:adjustViewBounds="false" 
    android:layout_marginBottom="10dp" 
    android:paddingLeft="@dimen/activity_horizontal_margin" 
    android:paddingRight="@dimen/activity_horizontal_margin" 
    android:scaleType="fitCenter" /> 


</RelativeLayout> 

<com.getbase.floatingactionbutton.FloatingActionsMenu 
    android:id="@+id/famMain" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    fab:fab_addButtonColorNormal="@color/material_orange" 
    fab:fab_addButtonSize="normal" 
    fab:fab_addButtonStrokeVisible="true" 
    fab:fab_expandDirection="up" 
    android:layout_gravity="bottom|end"> 

<com.getbase.floatingactionbutton.FloatingActionButton 
    android:id="@+id/fab_random" 
    android:src="@drawable/ic_random" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    fab:fab_colorNormal="@color/material_orange" 
    fab:fab_size="mini"/> 

<com.getbase.floatingactionbutton.FloatingActionButton 
    android:id="@+id/fab_download" 
    android:src="@drawable/ic_download" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    fab:fab_colorNormal="@color/material_orange" 
    fab:fab_size="mini"/> 

<com.getbase.floatingactionbutton.FloatingActionButton 
    android:id="@+id/fab_browser" 
    android:src="@drawable/ic_open_browser" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    fab:fab_colorNormal="@color/material_orange" 
    fab:fab_size="mini"/> 

</com.getbase.floatingactionbutton.FloatingActionsMenu> 

sau đó trong lớp Java của tôi tôi bắt đầu FloatingActionsMenu tôi với

FloatingActionsMenu famView = (FloatingActionsMenu) getActivity().findViewById(R.id.famMain); 

sau đó tôi đặt nó là Snackbar tôi với

Snackbar.make(famView, "Hover text copied to clipboard", Snackbar.LENGTH_SHORT).show(); 

Trả lời

8

Lý do các Snackbar được bao phủ rộng FloatingActionMenu là bởi vì bạn đang thiết mà làm chế độ xem các Snackbar:

Snackbar.make(famView, "Hover text copied to clipboard", Snackbar.LENGTH_SHORT).show(); 

Những gì bạn thực sự cần phải làm ở đây là thêm một CoordinatorLayout ở dưới cùng của bạn bố trí sẽ được sử dụng để hiển thị Snackbar. Bạn có thể thiết lập điều này theo kiểu LinearLayout để nó xuất hiện bên dưới mọi thứ khác. Dưới đây là một phiên bản chỉnh sửa của XML của bạn:

<LinearLayout 
    xmlns:android="http://schemas.android.com/apk/res/android" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    android:orientation="vertical"> 

    <android.support.design.widget.CoordinatorLayout 
     xmlns:fab="http://schemas.android.com/apk/res-auto" 
     android:id="@+id/coordinatorLayout" 
     android:layout_height="0dp" 
     android:layout_width="match_parent" 
     android:layout_weight="1"> 

     <RelativeLayout 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content"> 
      <TextView 
       android:id="@+id/title" 
       android:layout_width="wrap_content" 
       android:layout_height="wrap_content" 
       android:gravity="center_horizontal" 
       android:paddingLeft="@dimen/activity_horizontal_margin" 
       android:paddingRight="@dimen/activity_horizontal_margin" 
       android:text="Test" 
       android:textAppearance="?android:textAppearanceLarge" 
       android:layout_centerHorizontal="true" /> 

      <TextView 
       android:id="@+id/alt" 
       android:layout_width="wrap_content" 
       android:layout_height="wrap_content" 
       android:layout_below="@+id/title" 
       android:layout_centerHorizontal="true" 
       android:layout_gravity="center_horizontal" 
       android:fadeScrollbars="false" 
       android:gravity="center" 
       android:maxLines="4" 
       android:textColor="@android:color/black" 
       android:paddingBottom="13dp" 
       android:paddingLeft="@dimen/activity_horizontal_margin" 
       android:paddingRight="@dimen/activity_horizontal_margin" 
       android:scrollbars="vertical" 
       android:text="Test Alt" 
       android:textAppearance="?android:textAppearanceMedium" /> 

      <ImageView 
       android:id="@+id/imageView" 
       android:layout_width="match_parent" 
       android:layout_height="match_parent" 
       android:layout_below="@+id/alt" 
       android:adjustViewBounds="false" 
       android:layout_marginBottom="10dp" 
       android:paddingLeft="@dimen/activity_horizontal_margin" 
       android:paddingRight="@dimen/activity_horizontal_margin" 
       android:scaleType="fitCenter" /> 


     </RelativeLayout> 

     <com.getbase.floatingactionbutton.FloatingActionsMenu 
      android:id="@+id/famMain" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      fab:fab_addButtonColorNormal="@android:color/black" 
      fab:fab_addButtonSize="normal" 
      fab:fab_addButtonStrokeVisible="true" 
      fab:fab_expandDirection="up" 
      android:layout_gravity="bottom|end"> 

      <com.getbase.floatingactionbutton.FloatingActionButton 
       android:id="@+id/fab_random" 
       android:layout_width="wrap_content" 
       android:layout_height="wrap_content" 
       fab:fab_colorNormal="@android:color/black" 
       fab:fab_size="mini"/> 

      <com.getbase.floatingactionbutton.FloatingActionButton 
       android:id="@+id/fab_download" 
       android:layout_width="wrap_content" 
       android:layout_height="wrap_content" 
       fab:fab_colorNormal="@android:color/black" 
       fab:fab_size="mini"/> 

      <com.getbase.floatingactionbutton.FloatingActionButton 
       android:id="@+id/fab_browser" 
       android:layout_width="wrap_content" 
       android:layout_height="wrap_content" 
       fab:fab_colorNormal="@android:color/black" 
       fab:fab_size="mini"/> 

     </com.getbase.floatingactionbutton.FloatingActionsMenu> 

     <android.support.design.widget.FloatingActionButton 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:id="@+id/testFAB" 
      android:layout_gravity="bottom|start"/> 

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

    <android.support.design.widget.CoordinatorLayout 
     android:id="@+id/snackbar" 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content"/> 
</LinearLayout> 

Sau đó, bạn có thể có được cái nhìn snackbar như thế này:

CoordinatorLayout snackbar = (CoordinatorLayout) findViewById(R.id.snackbar); 

Và làm cho nó như thế này:

Snackbar.make(snackbar, "Hover text copied to clipboard", Snackbar.LENGTH_SHORT).show(); 
Các vấn đề liên quan