在android中创建给定形状的图像视图

pieyvz9o  于 2021-07-03  发布在  Java
关注(0)|答案(1)|浏览(374)


我需要在android中创建这个特定形状的imageview。如果可以裁剪这个形状的图像,那么它也很好。请帮帮我好吗?

khbbv19g

khbbv19g1#

这是整套的

  1. <FrameLayout
  2. android:layout_width="match_parent"
  3. android:layout_height="match_parent">
  4. <ImageView
  5. android:id="@+id/imageView"
  6. android:layout_width="match_parent"
  7. android:layout_height="match_parent"
  8. android:scaleType="fitXY"
  9. android:src="@drawable/gohan" />
  10. <ImageView
  11. android:layout_width="match_parent"
  12. android:layout_height="match_parent"
  13. android:scaleType="fitXY"
  14. android:src="@drawable/triangle_shape" />
  15. </FrameLayout>

triangle_shape.xml这将在您的 drawable 目录

  1. <?xml version="1.0" encoding="utf-8"?>
  2. <layer-list xmlns:android="http://schemas.android.com/apk/res/android">
  3. <item>
  4. <rotate
  5. android:fromDegrees="-70" // you will have to tweak this a little for adjustment
  6. android:pivotX="100%"
  7. android:pivotY="75%"
  8. android:toDegrees="40">
  9. <shape android:shape="rectangle">
  10. <stroke
  11. android:width="10dp"
  12. android:color="@android:color/transparent" />
  13. <solid android:color="@android:color/holo_blue_bright" />
  14. </shape>
  15. </rotate>
  16. </item>
  17. </layer-list>

输出

展开查看全部

相关问题