安卓:创建一个圆形的TextView? [英] Android: Creating a Circular TextView?

查看:577
本文介绍了安卓:创建一个圆形的TextView?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我现在简单的XML低于,但我想在3 TextViews内它是圆形的,而不是长方形的。

My current simple XML is below, however i would like the 3 TextViews within it to be circular, rather than rectangular.

我怎样才能改变我的code这样做?

How can I change my code to do so?

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical" >

    <TextView
        android:id="@+id/tvSummary1"
        android:layout_width="270dp"
        android:layout_height="60dp" >
    </TextView>

    <TextView
        android:id="@+id/tvSummary2"
        android:layout_width="270dp"
        android:layout_height="60dp" >
    </TextView>

    <TextView
        android:id="@+id/tvSummary3"
        android:layout_width="270dp"
        android:layout_height="60dp" >
    </TextView>

</LinearLayout>

注:我想要一个实际的不是曲边矩形如下图所示:

Note: I want an actual circle not the curved edge rectangle shown below:

编辑:

目前的code:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical" >

    <TextView
        android:id="@+id/tvSummary1"
        android:layout_width="270dp"
        android:layout_height="60dp"
        android:text=" " 
        android:gravity="left|center_vertical"
        android:background="@drawable/circle"/>

    <TextView
        android:id="@+id/tvSummary2"
        android:layout_width="270dp"
        android:layout_height="60dp"
        android:background="@drawable/circle" >
    </TextView>

    <TextView
        android:id="@+id/tvSummary3"
        android:layout_width="270dp"
        android:layout_height="60dp"
        android:background="@drawable/circle" >
    </TextView>

</LinearLayout>

电流输出:

推荐答案

创建一个 texview_design.xml 文件,并具有以下code填充它。把它放在RES /绘制。

Create an texview_design.xml file and populate it with the following code. Put it in res/drawable.

<shape xmlns:android="http://schemas.android.com/apk/res/android" >

        <solid android:color="#98AFC7" />

        <stroke
            android:width="2dp"
            android:color="#98AFC7" />

        <corners
            android:bottomLeftRadius="20dp"
            android:bottomRightRadius="20dp"
            android:topLeftRadius="20dp"
            android:topRightRadius="20dp" />

    </shape>

然后在你的主XML文件只需添加以下行的每个TextView的:

Then in your main XML file just add the following line for each TextView:

  android:background="@drawable/texview_design"


第二种方法(不推荐):  下载这个圈子,并将其放置在你的绘制文件夹,然后使你的 TextView中的背景。然后设置重力中心


Second way (not recommended): Download this circle and place it in your drawable folder and then make it your TextView's background. and then set the gravity to center.

然后,它会是这样的:

这篇关于安卓:创建一个圆形的TextView?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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