的Andr​​oid如何编程方式创建三角形和矩形? [英] Android how to create triangle and rectangle shape programatically?

查看:183
本文介绍了的Andr​​oid如何编程方式创建三角形和矩形?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我们如何创建气球形状绘制如下。在这里我们可以动态地改变它的颜色。

How can we create ballon drawable shape as below. where we can change the color of it dynamically.

推荐答案

这是 XML 三角矩形。保存绘制文件夹内。

Here it is XML for triangle and rectangle. save it inside drawable folder.

triangle.xml

<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android" >
    <item >
        <rotate
            android:fromDegrees="45"
            android:toDegrees="45"
            android:pivotX="-40%"
            android:pivotY="87%" >
            <shape
                android:shape="rectangle"  >
                <stroke android:color="@android:color/transparent" android:width="10dp"/>
                <solid
                    android:color="#000000"  />
            </shape>
        </rotate>
    </item>
</layer-list>

rectangle.xml

<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android" >
    <item> 
    <shape android:shape="rectangle">
      <solid android:color="#B2E3FA" /> 
    </shape>
  </item>
</layer-list>

布局作为您所需要的形状。

and layout for shape you require.

<RelativeLayout
        android:id="@+id/rlv1"
        android:layout_width="150dp"
        android:layout_height="50dp"
        android:background="@drawable/rectangle" />

    <RelativeLayout
        android:id="@+id/rlv2"
        android:layout_width="50dp"
        android:layout_height="50dp"  
        android:layout_below="@+id/rlv1"
        android:background="@drawable/triangle"
        android:rotation="180" />

根据您所需的设定保证金。

set margin according you required.

<一个href="https://looksok.word$p$pss.com/2013/08/24/android-triangle-arrow-defined-as-an-xml-shape/">Source

这篇关于的Andr​​oid如何编程方式创建三角形和矩形?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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