当我使用ScrollView和HorizontalScrollView使水平和垂直滚动都成为可能,并切换到横向时,RecyclerView不像纵向方向那样填充屏幕。
我在一行布局中使用元素的相对宽度,在纵向方向上一切看起来都很好。
片段布局。
一个行布局
我在一行布局中使用元素的相对宽度,在纵向方向上一切看起来都很好。
片段布局。
<?xml version="1.0" encoding="utf-8"?>
<ScrollView 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:orientation="horizontal"
android:scrollbars="vertical"
android:fillViewport="true">
<HorizontalScrollView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@drawable/table_border">
<androidx.recyclerview.widget.RecyclerView
android:id="@+id/tableView"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:scrollbarStyle="outsideOverlay"
android:scrollbars="horizontal"
android:background="@drawable/table_border"
tools:listitem="@layout/table_inventory_row"
/>
</HorizontalScrollView>
</ScrollView>
一个行布局
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="70dp"
android:weightSum="1"
android:orientation="horizontal">
<TextView
android:id="@+id/txtId"
android:layout_weight=".15"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_gravity="top"
android:text="@string/id"
android:textSize="18sp" />
<TextView
android:id="@+id/txtManager"
android:layout_width="0dp"
android:layout_weight=".25"
android:layout_height="match_parent"
android:layout_gravity="top"
android:text="@string/manager"
android:textSize="18sp" />
<TextView
android:id="@+id/txtCreatedDate"
android:layout_width="0dp"
android:layout_weight=".25"
android:layout_height="match_parent"
android:layout_gravity="top"
android:text="@string/created_on"
android:textAlignment="center"
android:textSize="18sp" />
<TextView
android:id="@+id/txtExecutionDate"
android:layout_width="0dp"
android:layout_weight=".25"
android:layout_height="match_parent"
android:layout_gravity="top"
android:text="@string/executed_on"
android:textAlignment="center"
android:textSize="18sp" />
<TextView
android:id="@+id/txtDone"
android:layout_width="0dp"
android:layout_weight=".1"
android:layout_height="match_parent"
android:layout_gravity="top"
android:text="@string/is_done"
android:textAlignment="center"
android:textSize="18sp" />
</LinearLayout>
public RecyclerView.ViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
View itemView = LayoutInflater.
from(parent.getContext()).
inflate(R.layout.table_inventory_row, parent, false);
return new RowViewHolder(itemView);
}
肖像 https://imgur.com/5VaEJ6S https://imgur.com/97WGJ1n
如您在截图中所见,我已将蓝色边框放置于水平滚动条上,并且它占据了整个屏幕,但是RecyclerView的宽度不匹配。
我该如何使RecyclerView占据父元素的整个宽度?