Andriod开发————圆角边框与圆角背景的实现方式
2014-08-29 15:23
351 查看
本文主要分享圆角边框与圆角背景的实现方式。该方式的实现,需要了解shape的使用,该部分的详细介绍,请阅读博客/article/1536001.html。文中有较详细的介绍。
【转载使用,请注明出处:http://blog.csdn.net/mahoking】
如下是演示的shape_layout.xml模板。
[html] view
plaincopy
<?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截图。
[html] view
plaincopy
<?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
[java] view
plaincopy
/**
*@describe 圆角边框、圆角背景的实现演示
*@date 2014-8-24 22:35:49
*/
public class RoundCornerActivity extends Activity{
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_01_round_corner);
}
}
activity_01_round_corner.xml
[html] view
plaincopy
<?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。
[html] view
plaincopy
<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>
运行该项目,效果如下:
【转载使用,请注明出处:http://blog.csdn.net/mahoking】
如下是演示的shape_layout.xml模板。
[html] view
plaincopy
<?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截图。
[html] view
plaincopy
<?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
[java] view
plaincopy
/**
*@describe 圆角边框、圆角背景的实现演示
*@date 2014-8-24 22:35:49
*/
public class RoundCornerActivity extends Activity{
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_01_round_corner);
}
}
activity_01_round_corner.xml
[html] view
plaincopy
<?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。
[html] view
plaincopy
<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>
运行该项目,效果如下:
相关文章推荐
- 【Android UI】案例02 圆角边框、圆角背景的实现(shape)
- GradientDrawable 可以用来通过程序方式给控件设置背景如圆角,边框等
- Android学习之 圆角边框的几种实现方式
- Android 圆角边框的实现方式汇总
- Anroid 界面边框圆角的实现方式
- android shape实现控件圆角,背景,边框等属性
- 【Android UI】案例02 圆角边框、圆角背景的实现(shape)
- Android技巧之shape实现控件圆角,背景,边框等属性
- android 开发技巧(10)--为背景添加圆角边框
- css实现可扩展的图片背景圆角边框,在IE6,IE7,Firefox下通过测试
- CSS实现表格边框阴影和背景渐变效果
- 不用css样式表和背景图片实现圆角矩形
- 不用图片实现圆角边框
- Flex程序实现背景贴图的两种方式 Two ways to implement sexy background/border for containers
- CSS实现表格边框阴影和背景渐变效果
- jQuery教程(九)使用java script(jQuery)实现圆角边框
- div+css实现圆角边框:
- div+css实现圆角边框
- DIV+CSS实现圆角边框
- 不用图片纯css实现圆角的一种方式