Fragment中嵌套使用Card View布局
先看效果:
Fragment的布局文件很简单,就一个RecyclerView布局
<android.support.v7.widget.RecyclerView
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/recycler_view"
android:layout_width="match_parent"
android:layout_height="match_parent">
</android.support.v7.widget.RecyclerView>
然后自己定义一个类(名字随便取的)
public class Fruit {
private String name;
private int imageId;
public Fruit (String name, int imageId){
this.name = name;
this.imageId = imageId;
}
public String getName() {
return name;
}
int getImageId() {
return imageId;
}
}
再写一个布局文件
<android.support.v7.widget.CardView
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="5dp"
app:cardCornerRadius="5dp">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center_horizontal"