Recyclerview is followed by the control
Effect
Finally, it realizes that the controls under RecyclerView will slide down as the content increases, and the controls below will stick to the bottom of the screen when they finally exceed the screen.
Code
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:orientation="vertical" android:id="@+id/activity_main" android:layout_width="match_parent" android:layout_height="wrap_content" > <android.support.v7.widget.RecyclerView android:layout_width="match_parent" android:layout_height="0dp" android:layout_weight="1" ></android.support.v7.widget.RecyclerView> <LinearLayout android:layout_width="match_parent" android:layout_height="wrap_content"> <EditText android:layout_width="0dp" android:layout_height="wrap_content" android:layout_weight="1" android:hint="Type something here" android:id="@+id/input_text" android:maxLines="2" /> <Button android:layout_width="wrap_content" android:layout_height="wrap_content" android:id="@+id/send" android:text="send" /> </LinearLayout> </LinearLayout>
Attention points
In fact, why do the following components change with RecyclerView?
Because we can see that the height of the outermost LinearLayout Android: layout "height is wrap" content ", it is actually adapting to the height of the whole RecyclerView.
inference
If you change the height of the outermost LinearLayout Android: layout "height to match" parent ", the controls under RecyclerView will remain at the bottom all the time
Code
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:orientation="vertical" android:id="@+id/activity_main" android:layout_width="match_parent" android:layout_height="match_parent" > <android.support.v7.widget.RecyclerView android:layout_width="match_parent" android:layout_height="0dp" android:layout_weight="1" android:id="@+id/msg_recycler_view" ></android.support.v7.widget.RecyclerView> <LinearLayout android:layout_width="match_parent" android:layout_height="wrap_content"> <EditText android:layout_width="0dp" android:layout_height="wrap_content" android:layout_weight="1" android:hint="Type something here" android:id="@+id/input_text" android:maxLines="2" /> <Button android:layout_width="wrap_content" android:layout_height="wrap_content" android:id="@+id/send" android:text="send" /> </LinearLayout> </LinearLayout>