Tor*_*ame 2 android listview material-design android-cardview
原谅我有任何错误.我是初学者.任何人都可以解释如何在android中的cardview布局内创建一个列表视图.android 6.0中的示例设置应用程序
我想在每个cardview布局中创建一个可滚动的cardview布局和listview项目.我在网上搜索得足够多,似乎没有任何帮助.如果您有任何解决方案,这将对我有所帮助.
最好的方法是使用RecyclerView垂直LinearLayoutManager(看起来与a 相同ListView但具有更好的性能)和一个固定的大小CardView.你的CardView遗嘱的xml 看起来像这样:
<android.support.v7.widget.CardView
android:layout_width="match_parent"
android:layout_height="wrap_content" >
<android.support.v7.widget.RecyclerView
android:id="@+id/recyclerview"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
</android.support.v7.widget.CardView>
Run Code Online (Sandbox Code Playgroud)
然后以编程方式将固定大小设置RecyclerView为true,设置LayoutManager并创建自定义RecyclerView.Adapter以填充RecyclerView的行:
RecyclerView recyclerView = parentView.findViewById(R.id.recyclerview);
recyclerView.setHasFixedSize(true);
LinearLayoutManager layoutManager = new LinearLayoutManager(context, LinearLayoutManager.VERTICAL, false);
recyclerView.setLayoutManager(layoutManager);
MyCustomAdapter adapter = new MyCustomAdapter(context, dataSet);
recyclerView.setAdapter(adapter);
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
6770 次 |
| 最近记录: |