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

Android使用shape使组件呈现出特殊效果的方法

程序员文章站 2023-08-25 13:25:03
本文实例讲述了android使用shape使组件呈现出特殊效果的方法。分享给大家供大家参考,具体如下: 使用到的布局文件

本文实例讲述了android使用shape使组件呈现出特殊效果的方法。分享给大家供大家参考,具体如下:

Android使用shape使组件呈现出特殊效果的方法

使用到的布局文件

<?xml version="1.0" encoding="utf-8"?>
<linearlayout xmlns:android="http://schemas.android.com/apk/res/android"
  android:layout_width="fill_parent"
  android:layout_height="fill_parent"
  android:orientation="vertical"
  android:background="#ffffff"
  android:gravity="center_horizontal">
  <textview
    android:id="@+id/text"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:textcolor="#000000"
    android:text="未使用效果"
    android:layout_margintop="30dp"
    />
  <edittext
    android:id="@+id/edit"
    android:layout_width="280dp"
    android:layout_height="wrap_content"
    android:textcolor="#000000"
    android:text="未使用效果 未使用效果 未使用效果 未使用效果 未使用效果 未使用效果"
    android:cursorvisible="true"
     />
  <textview
    android:id="@+id/text"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:textcolor="#000000"
    android:text="使用效果"
    android:layout_margintop="10dp"
    />
  <edittext
    android:id="@+id/edit2"
    android:layout_width="280dp"
    android:layout_height="wrap_content"
    android:textcolor="#000000"
    android:text="使用效果 使用效果 使用效果 使用效果 使用效果 使用效果 使用效果 使用效果"
    android:background="@drawable/shape"
    android:cursorvisible="true"
     />
</linearlayout>

使用到的shape文件

<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android" >
  <corners
    android:radius="10dp"
    />
  <gradient
    android:startcolor="#33cc00"
    android:endcolor="#666600"
    android:angle="45"
    />
  <padding
    android:left="5dp"
    android:top="5dp"
    android:right="5dp"
    android:bottom="5dp"
    />
  <stroke
    android:width="3dp"
    android:color="#ff3300"
    />
</shape>

在这里主要说一下shape文件中各项的功能

gradient主要设置背景颜色渐变。startcolor为起始颜色值,endcolor为结束颜色值,angle为渐变角度
padding主要设置组件里内容距离组件内边框的间距
stroke主要设置组件的边框。width为边框宽度,color为边框颜色

更多关于android相关内容感兴趣的读者可查看本站专题:《android开发入门与进阶教程》、《android布局layout技巧总结》、《android视图view技巧总结》、《android编程之activity操作技巧总结》、《android操作json格式数据技巧总结》、《android资源操作技巧汇总》及《android控件用法总结

希望本文所述对大家android程序设计有所帮助。