绘制三角形背景的android [英] Draw triangle background in android

查看:2579
本文介绍了绘制三角形背景的android的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要绘制布局的背景为三角形,就像你可以在图片中看到的。

I need to draw a background of layout as a triangle, like you can see in the picture.

我发现,他们做同样的事情的例子,但我不知道如何使它适应我的情况。这里是的例如

I've found an example where they do something similar, but I don't know how to adapt it to my case. Here is the example

谁能帮助我?最好的。

推荐答案

下面是与在图像面前右下角的三角形可绘制资源的一个例子。由于图像我使用了默认的Andr​​oid启动器图标。你可以使用任何其它图像。

Here is an example of a drawable resource with a triangle in the right bottom corner in front of an image. As the image I used the default android launcher icon. You can use any other image.

在创建资源triangle.xml文件/绘制这样的:

Create triangle.xml file in res/drawable like this:

<layer-list xmlns:android="http://schemas.android.com/apk/res/android" >
<item
    android:drawable="@drawable/ic_launcher">
</item>
<item>
    <rotate
        android:fromDegrees="-45"
        android:toDegrees="0"
        android:pivotX="150%"
        android:pivotY="20%" >
        <shape
            android:shape="rectangle" >
            <solid android:color="#ff0000" />
        </shape>
    </rotate>
</item>
</layer-list>

然后把它作为一个视图的背景属性:

Then use it as background attribute of a view:

android:background="@drawable/triangle"

这篇关于绘制三角形背景的android的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆