简体   繁体   中英

Show Card View inside Recycler View with previous and next object

I am trying to create a horizontal recyclerview with cardview like below where the main Card is in the center and the previous and the next card have a partial visibility. 和

Is it possible to achive this without having 3 cardviews in the one layout ? Thanks in advance

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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM