【问题标题】:how to make image view with three corner and shadow如何使用三个角和阴影制作图像视图
【发布时间】:2020-05-27 01:46:30
【问题描述】:

如何制作像这样只有三个角的图像 我尝试使用框架布局插入图像视图并使其成为原始图像的资源 添加另一个带有 3 个角的边框 src 的图像视图,但它不起作用

【问题讨论】:

    标签: android xml imageview material-components-android


    【解决方案1】:

    使用Material Components library,您可以使用MaterialShapeDrawable

    只需使用类似的东西:

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

    与:

      <style name="onlyonecorner">
        <item name="cornerFamily">rounded</item>
        <item name="cornerSize">50%</item>
        <item name="cornerSizeTopRight">0dp</item>
      </style>
    

    ShapeableImageView 需要最低版本 1.2.0-alpha03

    【讨论】:

    • 关于影子的任何建议
    • 你找到任何关于影子的解决方案了吗? @KarimAta
    【解决方案2】:

    您可以尝试使用 Glide 或 Picasso 创建圆角位图。在这种情况下,您可以编写转换。例如,请参阅Make ImageView with Round Corner Using picasso

    然后您可以创建带有阴影的图像。之后将一张图片重叠在另一张图片上。

    【讨论】:

    • 我不想做圆我希望它有三个角
    • @KarimAta,是的,我的意思是你自己的一个角落的转变(如果可能的话)。或者创建一个圆圈并在右上角覆盖图像的 1/4。
    【解决方案3】:

    你可以这样使用:

    <androidx.constraintlayout.widget.ConstraintLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:background="#587E9B">
    
    
        <Button
            android:id="@+id/button5"
            android:layout_width="0dp"
            android:layout_height="0dp"
            app:layout_constraintHeight_percent="0.4"
            app:layout_constraintDimensionRatio="1:1"
            android:text="Button"
            android:background="@drawable/my_shape"
            app:layout_constraintBottom_toBottomOf="parent"
            app:layout_constraintEnd_toEndOf="parent"
            app:layout_constraintHorizontal_bias="0.5"
            app:layout_constraintStart_toStartOf="parent"
            app:layout_constraintTop_toTopOf="parent" />
    
    
    </androidx.constraintlayout.widget.ConstraintLayout>
    

    drawable/my_shape

    <?xml version="1.0" encoding="utf-8"?>
    <shape xmlns:android="http://schemas.android.com/apk/res/android"
    android:shape="rectangle">
    
    <corners android:radius="12dp" />
    <solid android:color="#CF2525" />
    <corners
        android:topLeftRadius="60dp"
        android:bottomRightRadius="60dp"
        android:bottomLeftRadius="60dp"/>
    <stroke
        android:width="1dp"
        android:color="@android:color/black" />
    
    </shape>
    

    这是它的外观:

    现在你需要做的就是改变corners里面的drawable/my_shape

    【讨论】:

    • 我想要三个角的图像而不是其他视图
    • 也许你可以像in this answer这样使用cardView
    • 另一个好答案here
    猜你喜欢
    • 1970-01-01
    • 2018-12-16
    • 2011-12-25
    • 2023-04-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多