Android实现矩形设置菜单

来源:互联网 发布:pp助手和淘宝手机助手 编辑:程序博客网 时间:2024/05/21 08:00

 

xml Layout

 

Xml代码 
  1. <?xml version="1.0" encoding="utf-8"?>  
  2. <ScrollView xmlns:Android="http://schemas.android.com/apk/res/android"  
  3.     android:layout_width="fill_parent" android:layout_height="fill_parent">  
  4.   
  5.     <LinearLayout android:id="@+id/all_details"  
  6.         android:layout_width="fill_parent" android:layout_height="fill_parent"  
  7.         android:orientation="vertical">  
  8.         <TextView android:text="@string/settings"  
  9.             android:layout_width="fill_parent" android:layout_height="wrap_content"  
  10.             android:layout_marginLeft="10px" android:id="@+id/settingsText"  
  11.             android:textSize="20sp" android:textStyle="bold" android:layout_marginBottom="10dip">  
  12.         </TextView>  
  13.         <RelativeLayout android:layout_width="fill_parent"  
  14.             android:layout_height="wrap_content" android:orientation="horizontal"  
  15.             android:layout_gravity="center_vertical" android:background="@drawable/imagetop"  
  16.             android:layout_marginLeft="10px"  
  17.             android:layout_marginRight="10px" android:paddingLeft="10px">  
  18.             <CheckBox android:id="@+id/firewall_checkBox" android:layout_width="@android:dimen/app_icon_size"  
  19.                 android:layout_height="@android:dimen/app_icon_size"  
  20.                 android:layout_alignParentRight="true" android:scaleType="fitCenter"  
  21.                 android:layout_gravity="center" />  
  22.             <TextView android:id="@+id/apps_name" android:layout_width="wrap_content"  
  23.                 android:layout_height="wrap_content" android:textAppearance="?android:attr/textAppearanceMedium"  
  24.                 android:textColor="#000000" android:textSize="18dip"  
  25.                 android:layout_alignParentTop="true" android:layout_alignParentLeft="true"  
  26.                 android:paddingTop="10dip" android:paddingRight="6dip"  
  27.                 android:paddingLeft="6dip" android:layout_gravity="center"  
  28.                 android:text="@string/firewall_switch" />  
  29.   
  30.   
  31.         </RelativeLayout>  
  32.         <RelativeLayout android:layout_width="fill_parent"  
  33.             android:layout_height="wrap_content" android:orientation="horizontal"  
  34.             android:layout_gravity="center_vertical" android:background="@drawable/imagemid"  
  35.             android:layout_marginLeft="10px"   
  36.             android:layout_marginRight="10px" android:paddingLeft="10px">  
  37.             <CheckBox android:id="@+id/call_checkBox" android:layout_width="@android:dimen/app_icon_size"  
  38.                 android:layout_height="@android:dimen/app_icon_size"  
  39.                 android:layout_alignParentRight="true" android:scaleType="fitCenter"  
  40.                 android:layout_gravity="center" />  
  41.             <TextView android:id="@+id/apps_name" android:layout_width="wrap_content"  
  42.                 android:layout_height="wrap_content" android:textAppearance="?android:attr/textAppearanceMedium"  
  43.                 android:textColor="#000000" android:textSize="18dip"  
  44.                 android:layout_alignParentTop="true" android:layout_alignParentLeft="true"  
  45.                 android:paddingTop="10dip" android:paddingRight="6dip"  
  46.                 android:paddingLeft="6dip" android:layout_gravity="center"  
  47.                 android:text="@string/blockincomingcall"/>  
  48.   
  49.   
  50.         </RelativeLayout>  
  51.         <RelativeLayout android:layout_width="fill_parent"  
  52.             android:layout_height="wrap_content" android:orientation="horizontal"  
  53.             android:layout_gravity="center_vertical" android:background="@drawable/imagebottom"  
  54.             android:layout_marginLeft="10px"  
  55.             android:layout_marginRight="10px" android:paddingLeft="10px">  
  56.             <CheckBox android:id="@+id/sms_checkbox" android:layout_width="@android:dimen/app_icon_size"  
  57.                 android:layout_height="@android:dimen/app_icon_size"  
  58.                 android:layout_alignParentRight="true" android:scaleType="fitCenter"  
  59.                 android:layout_gravity="center" />  
  60.             <TextView android:id="@+id/apps_name" android:layout_width="wrap_content"  
  61.                 android:layout_height="wrap_content" android:textAppearance="?android:attr/textAppearanceMedium"  
  62.                 android:textColor="#000000" android:textSize="18dip"  
  63.                 android:layout_alignParentTop="true" android:layout_alignParentLeft="true"  
  64.                 android:paddingTop="10dip" android:paddingRight="6dip"  
  65.                 android:paddingLeft="6dip" android:layout_gravity="center"  
  66.                  android:text="@string/showcalllocation"/>  
  67.   
  68.   
  69.         </RelativeLayout>  
  70.   
  71.     </LinearLayout>  
  72. </ScrollView>  

 

imagetop.xml(保存于drawable)

 

Xml代码 
  1. <?xml version="1.0" encoding="utf-8"?>  
  2. <shape xmlns:android="http://schemas.android.com/apk/res/android">  
  3.     <gradient   
  4.         android:startColor="#FFFFFF"   
  5.         android:endColor="#CCCCCC"   
  6.         android:angle="270" android:centerY="0.75"  
  7.         />  
  8.    
  9.     <corners android:radius="1dp"  
  10.              android:bottomRightRadius="0dp"  
  11.              android:topRightRadius="7dp"  
  12.              android:bottomLeftRadius="0dp"  
  13.              android:topLeftRadius="7dp"  
  14.              />  
  15.    
  16.              <!--  
  17.     <corners android:radius="5dip" /> 
  18.     -->  
  19. </shape>  

 

imagemid.xml

 

Xml代码 
  1. <?xml version="1.0" encoding="utf-8"?>  
  2. <shape xmlns:android="http://schemas.android.com/apk/res/android">  
  3.     <gradient   
  4.         android:startColor="#FFFFFF"   
  5.         android:endColor="#CCCCCC"   
  6.         android:angle="270" android:centerY="0.75"  
  7.         />  
  8.   
  9. </shape>  

 

imagebottom.xml

 

Java代码 
  1. <?xml version="1.0" encoding="utf-8"?>  
  2. <shape xmlns:android="http://schemas.android.com/apk/res/android">  
  3.     <gradient   
  4.         android:startColor="#FFFFFF"   
  5.         android:endColor="#CCCCCC"   
  6.         android:angle="270" android:centerY="0.75"  
  7.         />  
  8.   
  9.     <corners android:radius="1dp"  
  10.              android:bottomRightRadius="7dp"  
  11.              android:topRightRadius="0dp"  
  12.              android:bottomLeftRadius="7dp"  
  13.              android:topLeftRadius="0dp"  
  14.              />  
  15. </shape>  
原文来自:http://dev.10086.cn/cmdn/wiki/index.php?doc-view-3631.html

原创粉丝点击