Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/kotlin/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Android 为图像添加圆角_Android_Kotlin - Fatal编程技术网

Android 为图像添加圆角

Android 为图像添加圆角,android,kotlin,Android,Kotlin,如何在图像中添加圆角和一点阴影,使其看起来像附件 以下是我在活动中的内容 <LinearLayout android:layout_width="wrap_content" android:layout_height="wrap_content" android:orientation="horizontal"> <!-- Content here --> <Image

如何在图像中添加圆角和一点阴影,使其看起来像附件

以下是我在活动中的内容

        <LinearLayout
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:orientation="horizontal">
        <!-- Content here -->

        <ImageView
            android:id="@+id/imageView1"
            android:layout_width="107dp"
            android:layout_height="166dp"
            android:layout_marginStart="20dp"
            android:elevation="5dp"
            android:scaleType="fitCenter"
            android:translationZ="12dp"
            android:layout_marginTop="15dp" />


你可以用现成的东西

或者定制背景

<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
    android:shape="rectangle">

    <!-- View background color -->
    <solid
        android:color="@color/colorPrimary" >
    </solid>
    <!-- The radius makes the corners rounded -->
    <corners
        android:radius="8dp" >
    </corners>

</shape>
 <ImageView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:background="@drawable/circle"/>

可以更改“角点半径”标记 然后将其标记为背景

<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
    android:shape="rectangle">

    <!-- View background color -->
    <solid
        android:color="@color/colorPrimary" >
    </solid>
    <!-- The radius makes the corners rounded -->
    <corners
        android:radius="8dp" >
    </corners>

</shape>
 <ImageView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:background="@drawable/circle"/>

您有不同的选择


  • 您可以使用
    cardwiew
    作为根布局
  • 您可以使用
    材质形状可移动的
    ()
  • 从的
    1.2.0-alpha03
    版本开始,您可以将
    ImageView
    更改为新的
    ShapeableImageView
比如:

  <com.google.android.material.imageview.ShapeableImageView
      ...
      app:shapeAppearanceOverlay="@style/roundedImageView"
      app:srcCompat="@drawable/ic_custom_image" />

这是否回答了您的问题?使用
cardwiew
作为根布局。。