【问题标题】:Creating an Image view of given shape in android在android中创建给定形状的图像视图
【发布时间】:2016-01-13 06:37:02
【问题描述】:

我需要在 Android 中创建这个特定形状的图像视图。如果可以以这种形状裁剪图像,那么它也很好。请帮我解决一下?

【问题讨论】:

  • 您需要进行自定义级别以供参考使用此链接github.com/siyamed/android-shape-imageview
  • 你有没有尝试过? atlease google 还是什么?
  • 是的,我认为@AnjaliTripathi 是对的,您可以在android-shape-imageview 中看到函数Bitmap Mask Based ImageViews 之一。所以你要做的就是提供一个形状和整张照片,然后你就可以得到你想要的图片了。
  • 简单的解决方案。为什么不让图像的那部分透明?

标签: android imageview crop


【解决方案1】:

这将是完整的集合

<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 这将在您的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>

输出

【讨论】:

    猜你喜欢
    • 2015-09-01
    • 1970-01-01
    • 2013-01-22
    • 2013-04-27
    • 1970-01-01
    • 2015-04-14
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多