Creating an Image view of given shape in android

时间秒杀一切 提交于 2021-02-05 06:41:06

问题


I need to create an imageview of this particular shape in Android. If cropping an image in this shape is possible, then also its fine. Please help me out with it?


回答1:


This will be the complete set

<FrameLayout
    android:layout_width="match_parent"
    android:layout_height="match_parent">


    <ImageView
        android:id="@+id/imageView"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:scaleType="fitXY"
        android:src="@drawable/gohan" />

    <ImageView
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:scaleType="fitXY"
        android:src="@drawable/triangle_shape" />
</FrameLayout>

triangle_shape.xml this will be inside your drawable directory

<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
    <item>
        <rotate
            android:fromDegrees="-70" // you will have to tweak this a little for adjustment
            android:pivotX="100%"
            android:pivotY="75%"
            android:toDegrees="40">
            <shape android:shape="rectangle">
                <stroke
                    android:width="10dp"
                    android:color="@android:color/transparent" />
                <solid android:color="@android:color/holo_blue_bright" />
            </shape>
        </rotate>
    </item>
</layer-list>

Output



来源:https://stackoverflow.com/questions/34759931/creating-an-image-view-of-given-shape-in-android

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!