android中textview的圆角 [英] Rounded corner for textview in android

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

问题描述

我有一个textview,希望它的角是圆形的.我已经知道可以使用android:background="@drawable/somefile"来完成.就我而言,此标记已包含在内,因此无法再次使用.例如android:background="@drawable/mydialogbox"已经可以在后台创建图像

I have a textview and want its corner to be in round shape. I already know it can be done using android:background="@drawable/somefile". In my case, this tag is already included so cannot use again. e.g android:background="@drawable/mydialogbox" is already there to create image in background

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="wrap_content"
    android:layout_height="fill_parent"
    android:layout_gravity="top"
    android:background="@drawable/mydialogbox"
    android:orientation="horizontal" >

    <TextView
        android:id="@+id/textview_name"
        android:layout_alignParentTop="true"
        android:layout_centerHorizontal="true" />

    </LinearLayout>

</RelativeLayout>

因此,当我也想使textview(textview_name)也具有圆角时,该如何实现.

so when I want textview(textview_name) also with round corner, how this can be achieved.

推荐答案

1)在drawable文件夹中创建rounded_corner.xml并添加以下内容,

1) Create rounded_corner.xml in the drawable folder and add the following content,

<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android" >         
   <stroke
          android:width="1dp"
          android:color="@color/common_border_color" />

   <solid android:color="#ffffff" />

   <padding
           android:left="1dp"
           android:right="1dp"
           android:bottom="1dp"
           android:top="1dp" />

   <corners android:radius="5dp" />
</shape>

2)在TextView背景属性中设置此可绘制对象,例如:

2) Set this drawable in the TextView background property.for example:

android:background="@drawable/rounded_corner"

我希望这对您有用.

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

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