Inside a RecyclerView
item row, you only need one CardView
because each time an item is created it'll inflate that layout for how many items have been passed into the RecyclerViewAdapter
but instead of having that CardView
's width being match_parent
or fill_parent
, you can assign it a width statically (for all screens) by assigning it a value.
<android.support.v7.widget.CardView
xmlns:card_view="http://schemas.android.com/apk/res-auto"
android:id="@+id/card_view"
android:layout_gravity="center"
android:layout_width="250dp"
android:layout_height="wrap_content"
card_view:cardCornerRadius="2dp">
....
</android.support.v7.widget.CardView>
In this case the CardView
has a width of 200dp
.
Note: Doing it this way will require you to change the dimensions based on the device that is being used.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.