简体   繁体   中英

how to make image view with three corner and shadow

图片

How to make an image with only three corners like this I tried using frame layout the insert image view and make it's resource with original image the add another image view with src of border that has 3 corner bu it doesn't work

With the Material Components library you can use the MaterialShapeDrawable .

Just use something like:

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

with:

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

在此处输入图片说明

The ShapeableImageView requires a minimum of version 1.2.0-alpha03 .

You can try to create a rounded bitmap with Glide or Picasso. In this case you can write transformation. See, for instance, Make ImageView with Round Corner Using picasso .

Then you can create an image with a shadow. After that overlap one image over another.

You can use something like this:

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

Here is how it will look:

在此处输入图片说明

Now all you need to do is to change the corners inside drawable/my_shape

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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