Make ImageView fit width of CardView

前端 未结 10 689
太阳男子
太阳男子 2020-12-04 11:00

I have a CardView with rounded corners, I want to have an ImageView at the top like shown in the example taken from the material design guidelines

10条回答
  •  被撕碎了的回忆
    2020-12-04 11:53

    i try to using combination with cardview and imageview, so it will be like this :

        android.support.v7.widget.CardView
                android:layout_width="match_parent"
                android:layout_height="160dp"
                android:layout_marginStart="16dp"
                android:layout_marginLeft="16dp"
                android:layout_marginTop="8dp"
                android:layout_marginEnd="16dp"
                android:layout_marginRight="16dp"
                app:cardCornerRadius="8dp"
                android:elevation="10dp"
                app:layout_constraintEnd_toEndOf="parent"
                app:layout_constraintStart_toStartOf="parent"
                app:layout_constraintTop_toBottomOf="@+id/textView">
    
                
    
      
    

    I just adding the corner radius and elevation attribute on cardview, and scaletype = centerCrop on image view

    Hope it will help

提交回复
热议问题