2017-10-07 111 views
-1

底部按鈕/某些視圖隱藏列表視圖底部部分。Android協調員佈局底欄隱藏列表視圖內

<android.support.design.widget.CoordinatorLayout xmlns:android="http://schemas.android.com/apk/res/android" 
      xmlns:app="http://schemas.android.com/apk/res-auto" 
      xmlns:tools="http://schemas.android.com/tools" 
      android:layout_width="match_parent" 
      android:layout_height="match_parent" 
      android:fitsSystemWindows="true"> 

    <android.support.design.widget.AppBarLayout 


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

     <android.support.v4.widget.NestedScrollView xmlns:android="http://schemas.android.com/apk/res/android" 
       xmlns:app="http://schemas.android.com/apk/res-auto" 
       xmlns:tools="http://schemas.android.com/tools" 
       android:layout_width="match_parent" 
       android:layout_height="match_parent" 
       app:layout_behavior="@string/appbar_scrolling_view_behavior" 
       tools:context="example.design.activities.DetailsActivity" 
       android:background="@color/grey"> 

       <android.support.v7.widget.RecyclerView 
        android:paddingTop="80dp" 
        android:layout_width="match_parent" 
        android:layout_height="match_parent"/> 


      </android.support.v4.widget.NestedScrollView> 


     <RelativeLayout 
       android:layout_width="match_parent" 
       android:layout_height="match_parent" 
       android:layout_gravity="bottom" 
       android:gravity="bottom"> 

       <!-- Add to cart button --> 
       <android.support.v7.widget.AppCompatButton 
        android:id="@+id/ssssss" 
        android:layout_width="fill_parent" 
        android:layout_height="wrap_content" 
        android:padding="20dp" 
        android:text="ADD TO CART" 
        android:backgroundTint="@color/colorPrimary" 
        android:textColor="@color/white" 
        android:layout_alignParentBottom="true" 
        android:visibility="visible" /> 

      </RelativeLayout> 

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

enter image description here

我會仰視圖中可見和不可見基於條件。

如何調整我的列表視圖滾動更多,如果底部欄可見?

+0

你能描述更 –

+0

我的菜單項列表,一旦用戶選擇的項目,我將標誌着一個按鈕可見。圖像顯示可見按鈕。此時列表視圖的最後一個元素隱藏在按鈕後面。我想把它放在最上面/滾動更多。 –

+0

你有沒有檢查[this](https://stackoverflow.com/questions/33668144/position-view-below-another-view-in-coordinatorlayout-in-android)。 – paril

回答

1

您可以在您的NestedScrollView中添加android:clipToPadding = "false"。 而當您顯示底部按鈕時,您可以動態地爲NestedScrollview添加底部填充,其值等於底部按鈕的高度。

nestedScrollView.setPadding(yourPadding, yourPadding,yourPadding, btn.getMeasuredHeight()) 
+0

hi getMeasuredHeight返回0? –

+0

只有問題是獲得高度。休息很好。 –

0

您應該使用layout_anchor更改NestedScrollView,如下所示。

<android.support.v4.widget.NestedScrollView xmlns:android="http://schemas.android.com/apk/res/android" 
    xmlns:app="http://schemas.android.com/apk/res-auto" 
    xmlns:tools="http://schemas.android.com/tools" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    app:layout_behavior="@string/appbar_scrolling_view_behavior" 
    tools:context="example.design.activities.DetailsActivity" 
    android:background="@color/colorPrimary" 
    app:layout_anchor="@+id/relative_view" 
    app:layout_anchorGravity="top"> 

    <android.support.v7.widget.RecyclerView 
     android:id="@+id/recycler_view" 
     android:paddingTop="80dp" 
     android:layout_width="match_parent" 
     android:layout_height="match_parent"/> 


</android.support.v4.widget.NestedScrollView> 

它將scrollview放在您的底部欄頂部,根據您的方面。

+0

如果添加此頂部摺疊工具欄視圖給出閃爍效果。上卷之後。 –

1

我認爲這將解決您的問題,

<?xml version="1.0" encoding="utf-8"?> 
<android.support.design.widget.CoordinatorLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    xmlns:app="http://schemas.android.com/apk/res-auto" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent"> 

    <android.support.v4.widget.NestedScrollView 
     android:layout_width="match_parent" 
     android:layout_height="match_parent" 
     app:layout_behavior="@string/appbar_scrolling_view_behavior" 
     android:fillViewport="true" 
     android:background="@android:color/darker_gray"> 

     <RelativeLayout 
      android:layout_width="match_parent" 
      android:layout_height="match_parent" 
      android:orientation="vertical"> 

      <android.support.v7.widget.RecyclerView 
       android:layout_width="match_parent" 
       android:layout_alignParentTop="true" 
       android:layout_height="match_parent" 
       android:layout_above="@+id/ssssss"/> 

      <!-- Add to cart button --> 
      <android.support.v7.widget.AppCompatButton 
       android:id="@+id/ssssss" 
       android:layout_width="match_parent" 
       android:layout_height="wrap_content" 
       android:padding="20dp" 
       android:text="ADD TO CART" 
       android:layout_alignParentBottom="true" 
       android:backgroundTint="@color/colorPrimary" 
       android:textColor="@android:color/white" 

       android:visibility="visible" /> 

     </RelativeLayout> 


    </android.support.v4.widget.NestedScrollView> 




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

這裏是樣本輸出 enter image description here

注: 已添加android:fitsSystemWindows="true",所以你在你的回收站view.Instead您可以根據需要android:paddingTop="80dp"按照我的解決方案,只需將android:fillViewport="true"設置爲nestedScrollView,並且不需要用於回收站視圖的填充。 我希望這能解決您的問題

+0

這一個會在名單 –

+0

下哪一個底部視圖?因爲兩者都在相對佈局 –

+0

請嘗試問我。這是不對的。 –

0
<android.support.design.widget.CoordinatorLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    xmlns:app="http://schemas.android.com/apk/res-auto" 
    xmlns:tools="http://schemas.android.com/tools" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    android:fitsSystemWindows="true"> 


    <android.support.v4.widget.NestedScrollView xmlns:android="http://schemas.android.com/apk/res/android" 
     xmlns:app="http://schemas.android.com/apk/res-auto" 
     xmlns:tools="http://schemas.android.com/tools" 
     android:layout_width="match_parent" 
     android:layout_height="match_parent" 
     android:background="#EAEAEA" 
     android:fillViewport="true" 
     app:layout_behavior="@string/appbar_scrolling_view_behavior" 
     tools:context="example.design.activities.DetailsActivity"> 

     <RelativeLayout 
      android:layout_width="match_parent" 
      android:layout_height="match_parent"> 
      <!-- Add to cart button --> 
      <android.support.v7.widget.AppCompatButton 
       android:id="@+id/ssssss" 
       android:layout_width="fill_parent" 
       android:layout_height="wrap_content" 
       android:layout_alignParentBottom="true" 
       android:backgroundTint="@color/colorPrimary" 
       android:padding="20dp" 
       android:text="ADD TO CART" 
       android:textColor="#FFFFFF" 
       android:visibility="visible" /> 

      <android.support.v7.widget.RecyclerView 
       android:layout_width="match_parent" 
       android:layout_height="match_parent" 
       android:layout_above="@+id/ssssss" 
       android:layout_alignParentTop="true" 
       android:paddingTop="80dp" /> 
     </RelativeLayout> 

    </android.support.v4.widget.NestedScrollView> 


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