所以我在使用布局文件中的 RecyclerView 时遇到了一些问题
这里是:
<android.support.v7.widget.RecyclerView android:id="@+id/chat_listview" android:layout_width="match_parent" android:layout_height="wrap_content" android:paddingRight="@dimen/abc_action_bar_default_padding_material" android:paddingLeft="@dimen/abc_action_bar_default_padding_material" /> <LinearLayout android:layout_below="@id/chat_listview" android:layout_width="match_parent" android:layout_height="@dimen/bottom_bar_height" android:orientation="horizontal" > <EditText android:id="@+id/chat_input_edittext" android:layout_weight="7" android:layout_width="0dp" android:layout_height="match_parent" android:inputType="textAutoCorrect" /> <Button android:id="@+id/chat_send_button" android:layout_weight="1" android:layout_width="0dp" android:layout_height="match_parent" android:background="@drawable/ic_action_send_now" /> </LinearLayout>
RecyclerView 可见且可滚动,但 LinearLayout 和内部的 View 不可见...我尝试了很多方法,但到目前为止没有任何效果。
你们中的任何人都可以指出我正确的方向吗?
非常感谢!
最佳答案
当 RecyclerView 被绘制时,它会在绘制下一个元素之前计算屏幕上所有剩余的尺寸给自己,并且在绘制其他元素后不再重新计算,将它们留在屏幕之外。
诀窍是首先绘制所有其他元素,最后留下 RecyclerView。 FrameLayout 不再起作用,因此使用相对布局并将 RecyclerView 放在 XML 布局文件的最后。
在 RecyclerView 下方添加带有按钮的栏的示例:
<?xml version="1.0" encoding="utf-8"?>
<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"
android:padding="16dp"
tools:context=".MainActivity"
>
<LinearLayout
android:id="@+id/pagination_btns"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:layout_alignParentBottom="true"> //HERE YOU ALIGN THIS ELEMENT TO THE BOTTOM OF THE PARENT
<Button
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:text="@string/previous_btn_label"/>
<Space
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1"/>
<Button
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:text="@string/next_btn_label"/>
</LinearLayout>
<android.support.v7.widget.RecyclerView
android:id="@+id/items_recycler_view"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:scrollbars="vertical"
android:layout_above="@id/pagination_btns"/> //HERE YOU ALIGN THE RECYCLERVIEW ABOVE THE PAGINATION BAR
</RelativeLayout>
关于java - RecyclerView 占用所有屏幕空间,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27464073/