欢迎访问移动开发之家(rcyd.net),关注移动开发教程。移动开发之家  移动开发问答|  每日更新
页面位置 : > > 内容正文

Android开发技巧四--圆角化控件,让它看起来更美,android开发技巧

来源: 开发者 投稿于  被查看 18334 次 评论:29

Android开发技巧四--圆角化控件,让它看起来更美,android开发技巧


当需要为应用程序UI控件选择背景的时候,开发者会添加自定义的颜色和形状来代替系统的默认样式,

圆角边框看起来是很不错的效果,开发者只需要添加几行代码,就可以在应用程序中使用这种效果。

下面我们做一个例子看一看,新建一个main.xml代码:

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:id="@+id/container"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical" >

    <Button
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_gravity="center"
        android:layout_marginTop="50dp"
        android:background="@drawable/button_rounded_background"
        android:gravity="center_vertical"
        android:padding="10dp"
        android:text="Hello,RoundCornerDemo"
        android:textColor="#FFFFFF" />

</LinearLayout>

其中我们为背景属性指定了drawable值,但是这个值并不是一个图片,而是一个xml文件。文件代码如下:

<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android" >

    <solid android:color="#02A712" />

    <corners android:radius="15dp" />

</shape>

仅仅只是两行代码。让我们看一下效果吧:


是不是比方方正正的默认样式温和柔美多了!

喜欢的朋友可以关注我!多谢支持!

相关频道:

用户评论