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

3

enter image description here

我需要在Android中创建一个特定形状的ImageView。如果可以裁剪成这种形状的图片,那也可以。请帮我解决这个问题?


你需要根据自己的需求进行定制,可以参考这个链接:https://github.com/siyamed/android-shape-imageview。 - Anjali Tripathi
你尝试过什么吗?至少谷歌或其他搜索引擎了解一下吗? - user1140237
是的,我认为@AnjaliTripathi是正确的,你可以在android-shape-imageview中看到一个函数Bitmap Mask Based ImageViews。所以你应该提供一个形状和一张完整的照片,然后你就可以得到想要的图片了。 - Dennis Lu
简单的解决方案。为什么不将图像的那一部分设为透明? - Ketan Ahir
1个回答

2
这将是完整的一套。
<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>
将位于您的drawable目录中。
<?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>

输出 gohan


网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接