繁体   English   中英

如何使具有图像视图的卡片视图具有圆角

[英]How to make an card view that has an image view have rounded corners

上周我只是想弄清楚如何使这个transition_preview图像视图具有一个随卡片视图增长的圆角。 我尝试使用Glide提供给我们的 roundedCorner 解决方案,但我似乎无法解决该问题,当它扩展时,它有这个奇怪的空间,请参阅留下的图像。

这是我在那部分的代码:我怎样才能使它变得圆润? 我尝试了这个解决方案,但没有给我任何问题。 我不想要这种行为,但要扩展StackOverflow 问题

<androidx.constraintlayout.widget.ConstraintLayout
            android:id="@+id/view"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:clipChildren="false">
            <ImageView
                android:id="@+id/back_btn"
                android:contentDescription="@string/back_button"
                android:src="@drawable/ic_launcher_background"
                app:layout_constraintStart_toStartOf="parent"
                app:layout_constraintTop_toTopOf="parent" />

            <androidx.cardview.widget.CardView
                android:id="@+id/video_preview"
                android:layout_width="0dp"
                android:layout_height="0dp"
                android:layout_marginStart="80dp"
                android:layout_marginEnd="80dp"
                app:cardCornerRadius="20dp"
                app:cardElevation="0dp"
                app:layout_constraintDimensionRatio="H,4:5"
                app:layout_constraintEnd_toEndOf="parent"
                app:layout_constraintStart_toStartOf="parent"
                app:layout_constraintWidth_max="@dimen/preview_max_width"
                tools:layout_editor_absoluteY="69dp">

                <FrameLayout
                    android:layout_width="match_parent"
                    android:layout_height="match_parent">

                    <FrameLayout
                        android:id="@+id/video_container"
                        android:layout_width="match_parent"
                        android:layout_height="match_parent"
                        android:background="#000000" />

                    <ImageView
                        android:id="@+id/transition_preview"
                        android:layout_width="match_parent"
                        android:layout_height="match_parent"
                        android:scaleType="centerCrop" />
                </FrameLayout>
            </androidx.cardview.widget.CardView>

</androidx.constraintlayout.widget.ConstraintLayout>

使用材质卡视图作为圆角半径

<com.google.android.material.card.MaterialCardView
    android:id="@+id/userCard"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:layout_marginTop="4dp"
    app:cardCornerRadius="5dp"
    android:layout_marginBottom="4dp"
    app:layout_constraintStart_toStartOf="parent"
    app:layout_constraintTop_toTopOf="parent"
    app:layout_constraintEnd_toEndOf="parent">
    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:orientation="horizontal">

    <ImageView
        android:id="@+id/avtar"
        android:layout_width="50dp"
        android:layout_height="50dp"
        android:src="@mipmap/ic_launcher"
        android:layout_marginTop="10dp"
        android:layout_marginStart="8dp"
        android:layout_marginBottom="10dp"
        android:layout_gravity="center_vertical" />
    <TextView
        android:id="@+id/userName"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:textSize="18sp"
        android:layout_gravity="center_vertical"
        android:layout_marginStart="16dp"
        android:text="Hello"/>
    </LinearLayout>
</com.google.android.material.card.MaterialCardView>

根据您的要求添加您的图像。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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