简体   繁体   中英

RecyclerView Hiding LinearLayout

I am using RecyclerView and LinearLayout in one of my Quote Application like below.

 <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent" android:layout_height="match_parent" > <LinearLayout android:background="@color/colorPrimary" android:layout_alignParentBottom="true" android:id="@+id/pageNavLayout" android:orientation="horizontal" android:layout_width="match_parent" android:layout_height="40dp"> <RelativeLayout android:layout_weight="1" android:id="@+id/butPrev" style="@style/SelectableItemBackground" android:clickable="true" android:layout_width="0dp" android:layout_height="match_parent"> <ImageView android:layout_centerInParent="true" android:scaleType="fitCenter" android:src="@drawable/ic_keyboard_arrow_left_white_24dp" android:layout_width="match_parent" android:layout_height="match_parent" /> </RelativeLayout> <View android:background="#ffffff" android:layout_width="1dp" android:layout_height="match_parent"/> <TextView android:id="@+id/textPageCount" android:clickable="true" style="@style/SelectableItemBackground" android:padding="8dp" android:textSize="16sp" android:textColor="@android:color/white" android:text="Page 1 0f 67" android:layout_width="wrap_content" android:layout_height="wrap_content" /> <View android:background="#ffffff" android:layout_width="1dp" android:layout_height="match_parent"/> <RelativeLayout android:layout_weight="1" style="@style/SelectableItemBackground" android:clickable="true" android:id="@+id/butNext" android:layout_width="0dp" android:layout_height="match_parent"> <ImageView android:layout_centerInParent="true" android:src="@drawable/ic_keyboard_arrow_right_white_24dp" android:layout_width="match_parent" android:layout_height="match_parent" /> </RelativeLayout> </LinearLayout> <android.support.v7.widget.RecyclerView android:layout_marginTop="4dp" android:layout_marginBottom="4dp" android:layout_above="@id/pageNavLayout" android:id="@+id/listQuoteView" android:layout_width="match_parent" android:layout_height="match_parent"></android.support.v7.widget.RecyclerView> </RelativeLayout> 

Now when I press next button and RecyclerView List another Quote...its hiding MY LinearLayout for some time and when I scroll it, its showing it. I have used LinearLayout for my bottom bar. What I am missing and What I should do for show always bottom bar ?

Thanks

Try this.

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

   <android.support.v7.widget.RecyclerView
       android:layout_marginTop="4dp"
       android:layout_marginBottom="4dp"
       android:id="@+id/listQuoteView"
       android:layout_width="match_parent"
       android:weight="1"
       android:layout_height="0dp">
     </android.support.v7.widget.RecyclerView>

<LinearLayout
  android:orientation="vertical"
  android:id="@+id/pageNavLayout"
  android:layout_width="match_parent"
  android:weight="1"
  android:layout_height="0dp">

    <LinearLayout
        android:background="@color/colorPrimary"
        android:orientation="horizontal"
        android:layout_width="match_parent"
        android:layout_height="40dp">


        <RelativeLayout
            android:layout_weight="1"
            android:id="@+id/butPrev"
            style="@style/SelectableItemBackground"
            android:clickable="true"
            android:layout_width="0dp"
            android:layout_height="match_parent">

            <ImageView
                android:layout_centerInParent="true"
                android:scaleType="fitCenter"
                android:src="@drawable/ic_keyboard_arrow_left_white_24dp"
                android:layout_width="match_parent"
                android:layout_height="match_parent" />
        </RelativeLayout>


        <View
            android:background="#ffffff"
            android:layout_width="1dp"
            android:layout_height="match_parent"/>

        <TextView
            android:id="@+id/textPageCount"
            android:clickable="true"
            style="@style/SelectableItemBackground"
            android:padding="8dp"
            android:textSize="16sp"
            android:textColor="@android:color/white"
            android:text="Page 1 0f 67"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content" />

        <View
            android:background="#ffffff"
            android:layout_width="1dp"
            android:layout_height="match_parent"/>

        <RelativeLayout
            android:layout_weight="1"
            style="@style/SelectableItemBackground"
            android:clickable="true"
            android:id="@+id/butNext"
            android:layout_width="0dp"
            android:layout_height="match_parent">

            <ImageView
                android:layout_centerInParent="true"
                android:src="@drawable/ic_keyboard_arrow_right_white_24dp"
                android:layout_width="match_parent"
                android:layout_height="match_parent" />
        </RelativeLayout>

    </LinearLayout>

</LinearLayout>   
</LinearLayout>

在您的RecyclerView添加android:layout_marginBottom="40dp"以使其始终可见,因为LinearLayout高度为40dp (根据您的代码)。

Here's an example of an element that's fixed to the bottom of the screen:

    <RelativeLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_alignParentBottom="true"
        android:gravity="center"
        android:background="#26ffffff"
        android:paddingTop="3dp"
        android:paddingBottom="3dp">
        <TextView
            android:id="@+id/today_last_sync"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:textSize="12sp"
            android:gravity="right"
            android:textColor="@color/white"/>
    </RelativeLayout>

You need to make sure that you are using the following setting on the child XML:

android:layout_alignParentBottom="true"

As well as the parent container having:

    android:layout_width="match_parent"
    android:layout_height="match_parent"

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM