【问题标题】:How to make an card view that has an image view have rounded corners如何使具有图像视图的卡片视图具有圆角
【发布时间】:2022-05-25 19:09:21
【问题描述】:

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

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

<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>

【问题讨论】:

    标签: android kotlin animation


    【解决方案1】:

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

    <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>
    

    根据您的要求添加图片。

    【讨论】:

      猜你喜欢
      • 2011-12-25
      • 1970-01-01
      • 2021-11-04
      • 2012-02-29
      • 1970-01-01
      • 2016-03-30
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多