欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页  >  移动技术

Android TextView(圆弧)边框和背景实例详解

程序员文章站 2024-03-01 10:54:28
 android textview 圆弧 效果图: 布局代码:

 android textview 圆弧

效果图:

Android TextView(圆弧)边框和背景实例详解Android TextView(圆弧)边框和背景实例详解

布局代码:

<textview 
          android:id="@+id/product_tag" 
          android:layout_width="wrap_content" 
          android:layout_height="wrap_content" 
          android:gravity="center" 
          android:singleline="true" 
          android:textsize="10sp" 
          android:textcolor="@color/label_orange" 
          android:layout_marginleft="10dp" 
          android:background="@drawable/shape_label_orange" 
          android:text="标签"/> 

样式代码:

弧度和背景主要靠background中的.xml文件实现

Android TextView(圆弧)边框和背景实例详解

1、

<?xml version="1.0" encoding="utf-8"?> 
<shape xmlns:android="http://schemas.android.com/apk/res/android"> 
 
  <!-- 实心 --> 
  <solid android:color="@android:color/white"/> 
  <!-- 边框 --> 
  <stroke 
      android:width="0.5dp" 
      android:color="@color/label_orange"/> 
  <!-- 圆角 --> 
  <corners android:radius="3dp"/> 
  <!-- 边距 --> 
  <padding 
      android:top="2dp" 
      android:bottom="2dp" 
      android:left="6dp" 
      android:right="6dp"/> 
 
</shape> 

2、Android TextView(圆弧)边框和背景实例详解

<?xml version="1.0" encoding="utf-8"?> 
<shape 
    xmlns:android="http://schemas.android.com/apk/res/android" 
    android:shape="oval" 
    android:uselevel="false"> 
 
  <!-- 实心 --> 
  <solid android:color="@color/label_round_orange" /> 
  <!-- 圆角 --> 
  <corners android:radius="360dp" /> 
  <!-- 边距 --> 
  <padding 
    android:bottom="1dp" 
    android:left="1dp" 
    android:right="1dp" 
    android:top="1dp" /> 
 
  <!-- 大小 --> 
  <size android:width="15dp" 
     android:height="15dp" /> 
 
</shape> 

感谢阅读,希望能帮助到大家,谢谢大家对本站的支持!