【Android UI】案例02 圆角边框、圆角背景的实现(shape)
来源:互联网 发布:上班不化妆 知乎 编辑:程序博客网 时间:2024/05/01 03:55
本文主要分享圆角边框与圆角背景的实现方式。该方式的实现,需要了解shape的使用,该部分的详细介绍,请阅读博客http://blog.csdn.net/mahoking/article/details/23672271。文中有较详细的介绍。
【转载使用,请注明出处:http://blog.csdn.net/mahoking】
如下是演示的shape_layout.xml模板。
<?xml version="1.0" encoding="utf-8"?><shape xmlns:android="http://schemas.android.com/apk/res/android" > <!-- 填充色 --> <solid android:color="#CCFF99"/><!-- 圆角 --><corners android:radius="10dp"/></shape>
为了显示的好看与协调,本案创建了多个shape_*.xml文件,各个shape_*.xml文件只是solid填充色的配置不同,读者可以根据自己的设计与喜好自行搭配。在本文的而最后,会展示相应Demo截图。
<?xml version="1.0" encoding="utf-8"?><shape xmlns:android="http://schemas.android.com/apk/res/android" > <!-- 填充色 --> <solid android:color="#FF9999"/><!-- 圆角 --><!-- android:radius 设置角的弧度,值越大角越圆--><corners android:radius="10dp"/></shape>
创建Activity(RoundCornerActivity),对应的布局文件为activity_01_round_corner.xml。
RoundCornerActivity
/** *@describe 圆角边框、圆角背景的实现演示 *@date 2014-8-24 22:35:49 */public class RoundCornerActivity extends Activity{@Overrideprotected void onCreate(Bundle savedInstanceState) {super.onCreate(savedInstanceState);setContentView(R.layout.activity_01_round_corner);}}
activity_01_round_corner.xml
<?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:layout_width="match_parent" android:layout_height="20dp" android:layout_marginLeft="15dp" android:layout_marginRight="15dp" android:layout_marginTop="5dp" android:background="@drawable/shape_01_round_corner_textview" android:gravity="center" android:text="圆角背景与边框演示" /> <LinearLayout android:layout_width="match_parent" android:layout_height="60dp" android:layout_marginLeft="15dp" android:layout_marginRight="15dp" android:layout_marginTop="10dp" android:background="@drawable/shape_01_round_corner_layout" > </LinearLayout> <TextView android:layout_width="match_parent" android:layout_height="20dp" android:layout_marginLeft="15dp" android:layout_marginRight="15dp" android:layout_marginTop="5dp" android:background="@drawable/shape_01_round_corner_textview" android:gravity="center" android:text="以下是特效演示" /> <LinearLayout android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_marginTop="10dp" android:orientation="horizontal" > <LinearLayout android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_marginLeft="5dp" android:layout_marginRight="5dp" android:layout_weight="1" android:orientation="vertical" > <TextView android:layout_width="match_parent" android:layout_height="120dp" android:background="@drawable/shape_01_round_corner_textview_ma" android:gravity="center" android:text="马" android:textSize="60dp" /> </LinearLayout> <LinearLayout android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_marginLeft="5dp" android:layout_marginRight="5dp" android:layout_weight="1" android:orientation="vertical" > <TextView android:layout_width="match_parent" android:layout_height="55dp" android:background="@drawable/shape_01_round_corner_textview_yi" android:gravity="center" android:text="意" android:textSize="30dp" /> <TextView android:layout_width="match_parent" android:layout_height="55dp" android:layout_marginTop="10dp" android:background="@drawable/shape_01_round_corner_textview_ran" android:gravity="center" android:text="然" android:textSize="30dp" /> </LinearLayout> </LinearLayout></LinearLayout>
切忌不要忘记在AndroidManifest.xml中注册该Activity。
<application android:allowBackup="true" android:icon="@drawable/uisharing_ico" android:label="@string/app_name" android:theme="@style/AppTheme" > <activity android:name="com.mahaochen.app.uisharing.example01.RoundCornerActivity" android:screenOrientation="portrait" android:label="@string/app_name"> <intent-filter> <action android:name="android.intent.action.MAIN" /> <category android:name="android.intent.category.LAUNCHER" /> </intent-filter> </activity> </application>
运行该项目,效果如下:
2 1
- 【Android UI】案例02 圆角边框、圆角背景的实现(shape)
- android shape实现控件圆角,背景,边框等属性
- android shape实现边框圆角
- Android技巧之shape实现控件圆角,背景,边框等属性
- android 圆角边框的实现及shape结构
- 圆角边框shape实现
- Android下基于XML的Graphics shape的高级UI设计,定义圆角背景等
- Android通过代码实现圆角边框shape
- Android实现圆角边框,shape的使用详解以及常用效果
- android里面shape属性用代码实现圆角背景的工具类
- android 圆角边框、渐变背景的TextView
- android 圆角边框、渐变背景的TextView
- Android中用shape做渐变,边框,圆角等效果
- 设置背景的圆角,边框
- 圆角边框,渐变背景的Textview
- android shape设置矩形边框圆角大于某个值无效的解决办法
- 用shape画一个圆角边框
- 圆角边框和背景
- OpenCV基础篇之像素访问
- mac10.9.4重设普通用户开机密码和root密码
- DDR3 ODT
- 手势
- day4,page25,total130
- 【Android UI】案例02 圆角边框、圆角背景的实现(shape)
- Linux显示文本的命令(cat, tac,more,less,head,tail,nl)
- Maven实战(六)——Gradle
- hg8245
- hdu 1394 Minimum Inversion Number
- C++设计模式之简单工厂模式
- Android小項目之--ListView與ListAcitivity完善論壇管理效果2(附源碼)
- 外置内存卡
- HashSet中equals()与hashCode()方法的重写