Android UI Case 02 Implementation of rounded borders, rounded backgrounds (shape)

Source: Internet
Author: User

This article mainly shares the fillet border and the rounded corner of the background implementation. The implementation of this approach requires an understanding of the use of shape, a detailed introduction to this section, please read the blog http://blog.csdn.net/mahoking/article/details/23672271. The article has a more detailed introduction.

"Reproduced use, please specify the source: http://blog.csdn.net/mahoking "
The following is a demo of the Shape_layout.xml template.

<?xml version= "1.0" encoding= "Utf-8"? ><shape xmlns:android= "Http://schemas.android.com/apk/res/android" >    <!--fill-    <solid android:color= "#CCFF99"/><!--fillet--><corners android:radius= " 10DP "/></shape>

In order to show the good looks and coordination, the case created a number of shape_*.xml files, each shape_*.xml file is only solid fill color configuration, readers can be based on their own design and preferences to match. At the end of this article, the demo will be displayed.

<?xml version= "1.0" encoding= "Utf-8"? ><shape xmlns:android= "Http://schemas.android.com/apk/res/android" >    <!--fill-    <solid android:color= "#FF9999"/><!--fillet--><!--Android:radius Set the radian of the angle, The larger the value, the more rounded--><corners android:radius= "10DP"/></shape>

Create activity (roundcorneractivity), the corresponding layout file is Activity_01_round_corner.xml.
Roundcorneractivity

/** * @describe  rounded border, rounded corner background demonstration * @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= "rounded background and border presentation"/> <l Inearlayout android:layout_width= "match_parent" android:layout_height= "60DP" Android:layout_marginlef t= "15DP" android:layout_marginright= "15DP" android:layout_margintop= "10DP" android:background= "@drawa         Ble/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= "to        Below is the special effects demo "/> <linearlayout android:layout_width=" match_parent "android:layout_height=" Wrap_content " android:layout_margintop= "10DP" android:orientation= "Horizontal" > <linearlayout Android             Oid: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=" 12 0DP "android:background=" @drawable/shape_01_round_corner_textview_ma "android:gravity=" Cente R "AndroiD:text= "Ma" android:textsize= "60DP"/> </LinearLayout> <linearlayout an Droid:layout_width= "Match_parent" android:layout_height= "Wrap_content" android:layout_marginleft= "5d P "android:layout_marginright=" 5DP "android:layout_weight=" 1 "android:orientation=" vertic Al "> <textview android:layout_width=" match_parent "android:layout_height=" 55DP "android:background=" @drawable/shape_01_round_corner_textview_yi "android:gravity=" cent Er "android:text=" meaning "android:textsize=" 30dp "/> <textview an Droid:layout_width= "Match_parent" android:layout_height= "55DP" android:layout_margintop= "10d P "android:background=" @drawable/shape_01_round_corner_textview_ran "android:gravity=" center "Android: text= "android:textsize=" 30DP "/> </LinearLayout> </linearlayout></linearlay Out>

Never forget to register the activity in the Androidmanifest.xml.

<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>


To run the project, the effect is as follows:



Android UI Case 02 Implementation of rounded borders, rounded backgrounds (shape)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.