我有一个应用程序来管理书籍集(如播放列表).
我想显示一个带有垂直RecyclerView的集合列表,并在每行内部显示一个水平RecyclerView中的书籍列表.
当我将内部水平RecyclerView的layout_height设置为300dp时,它会正确显示,但是当我将其设置为wrap_content时,它不会显示任何内容. 我需要使用wrap_content,因为我希望能够以编程方式更改布局管理器以在垂直和水平显示之间切换.

你知道我做错了什么吗?
我的片段布局:
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@color/white">
<com.twibit.ui.view.CustomSwipeToRefreshLayout
android:id="@+id/swipe_container"
android:layout_width="match_parent"
android:layout_height="match_parent">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<android.support.v7.widget.RecyclerView
android:id="@+id/shelf_collection_listview"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingTop="10dp"/>
</LinearLayout>
</com.twibit.ui.view.CustomSwipeToRefreshLayout>
</LinearLayout>
Run Code Online (Sandbox Code Playgroud)
集合元素布局:
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#FFF">
<!-- Simple Header -->
</RelativeLayout>
<FrameLayout
android:layout_width="match_parent"
android:layout_height="wrap_content">
<TextView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:text="@string/empty_collection"
android:id="@+id/empty_collection_tv"
android:visibility="gone"
android:gravity="center"/>
<android.support.v7.widget.RecyclerView
android:id="@+id/collection_book_listview"
android:layout_width="match_parent"
android:layout_height="wrap_content"/> <!-- android:layout_height="300dp" -->
</FrameLayout>
</LinearLayout>
Run Code Online (Sandbox Code Playgroud)
书目项目:
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="180dp"
android:layout_height="220dp"
android:layout_gravity="center">
<ImageView
android:id="@+id/shelf_item_cover"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:maxWidth="150dp"
android:maxHeight="200dp"
android:src="@drawable/placeholder"
android:contentDescription="@string/cover"
android:adjustViewBounds="true"
android:background="@android:drawable/dialog_holo_light_frame"/> …Run Code Online (Sandbox Code Playgroud) android android-layout android-support-library android-studio android-recyclerview
我想添加一些子视图(列表项),它们来自JSON格式的数据.每个子列表都在父列表项行下.如何RecyclerView为每个行项(包含子列表项的父项)填充它?
我尝试RecyclerView在RecyclerView父行中使用(用于填充子列表),但此处子视图不可见.
public class DigitizedPrescAdapter extends RecyclerView.Adapter<DigitizedPrescAdapter.ListItemViewHolder>{
private List<PrescriptionModal> prescriptionList;
MedicinesInPrescAdapter adapter;
public DigitizedPrescAdapter(List<PrescriptionModal> prescriptionListModal) {
if (prescriptionListModal == null) {
throw new IllegalArgumentException(
"PrescriptionList must not be null");
}
this.prescriptionList = prescriptionListModal;
}
@Override
public ListItemViewHolder onCreateViewHolder(
ViewGroup viewGroup, int viewType) {
View itemView = LayoutInflater.
from(viewGroup.getContext()).
inflate(R.layout.item_row_digitised_request,
viewGroup,
false);
return new ListItemViewHolder(itemView);
}
@Override
public void onBindViewHolder(
ListItemViewHolder viewHolder, int position) {
PrescriptionModal model = prescriptionList.get(position);
viewHolder.prescnum.setText("Prescription "+ ++position);
viewHolder.prescNo.setText("Prescription: "+model.getPrescriptionID()); …Run Code Online (Sandbox Code Playgroud) 我正在开发一个显示游戏列表的应用程序,在每个游戏的itemView中,我还有一个要显示的视频列表.预览和结构如下.

我部署了一个RecyclerView作为窗口根视图,然后对于视频,我使用了网格式的RecyclerView来显示,所以这里我们得到了一个嵌套的RecyclerView结构.
但是有麻烦,因为游戏之间的视频数量不一致,我不希望视频列表的RecyclerView能够滚动,所以最好的方法是使View的高度伸展动态取决于它有多少行.我听到一个令人失望的结论说,没有办法从互联网上实现这一目标.真的吗?任何替代方案可以这样做?
到目前为止关于这个问题,我不知道要解决它,所以我手动更改RecyclerView的高度作为临时解决方案.
videoGridRecyclerView.getLayoutParams().height = rowCount * 242;
Run Code Online (Sandbox Code Playgroud)
鉴于视频项目是完全相同的结构,如果这些RecyclerViews可以在屏幕上刷掉它后重新使用该视频的itemViews会很好,它将需要更好的性能提升.
然后我试着让一个特定的RecycledViewPool传播到每个嵌套的RecyclerViews.
public class MainActivity extends Activity {
private RecyclerView.RecycledViewPool mViewPool;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
// create the RecycledViewPool from first and re-use for each nested RecyclerViews.
mViewPool = new RecyclerView.RecycledViewPool();
...
}
}
Run Code Online (Sandbox Code Playgroud)
即使我完成了这项工作,我仍然注意到正在执行的onCreateViewHolder方法和膨胀计数器在我循环刷根RootlerView期间增加.
private static class VideoAdapter extends RecyclerView.Adapter<GridViewHolder> {
private List<Video> mVideoList;
private VideoAdapter(List<Video> videoList) {
mVideoList = videoList;
}
// this method would always invoke during i swipe the RecyclerView.
@Override
public GridViewHolder …Run Code Online (Sandbox Code Playgroud) android android-layout android-listview android-5.0-lollipop android-recyclerview
android ×3