怎样绘制圆通过XML绘制对象 - 安卓? [英] How can I draw circle through XML Drawable - Android?

查看:121
本文介绍了怎样绘制圆通过XML绘制对象 - 安卓?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想绘制圆的XML文件在Android的帮助,但圈内无法正常显示。下面code正呈现椭圆形。我怎样才能在XML文件中创建循环。

I'm trying to draw circle with the help of XML file in android, but circle is not displaying properly. Below code is showing Oval. How can I create circle in XML file.

<shape xmlns:android="http://schemas.android.com/apk/res/android"
    android:shape="oval"> 
    <gradient
        android:startColor="#FFFF0000"
        android:endColor="#80FF00FF"
        android:angle="45"/>
    <padding android:left="2dp"
        android:top="2dp"
        android:right="2dp"
        android:bottom="2dp" />
    <corners android:radius="10dip" />

</shape>

任何帮助将是AP preciable。

Any help would be appreciable.

推荐答案

您需要创建一个形状绘制中,看起来像被拉伸的文件夹:

You need to create a shape drawable in the drawable folder that looks something like:

<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android" android:shape="oval" >
    <gradient android:startColor="#FFFF0000" android:endColor="#80FF00FF"
        android:angle="270"/>
</shape>

(在这个例子中我已经保存了绘制的circle.xml,它会有一个渐变填充)

(For this example I have saved the drawable as circle.xml and it will have a gradient fill)

然后在你的布局,你需要定义一个视图,设置形状的背景:

Then in your layout you need to define a view and set the shape as the background:

<View android:layout_width="50dp"
    android:layout_height="50dp"
    android:background="@drawable/circle"/>

观定义形状的尺寸和尺寸。

The View defines the size and dimensions of the shape.

编辑 - 的code结果的截图

Edit - Screenshots of the result of the code

这篇关于怎样绘制圆通过XML绘制对象 - 安卓?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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