zoukankan      html  css  js  c++  java
  • android之RadioGroup

    radioGroup这控件在开发中也是常用到的

    RadioGroup 有时候比较有用.主要特征是给用户提供多选一机制。

    用微信举一个例子吧!

     1 <?xml version="1.0" encoding="utf-8"?>
     2 <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
     3     android:layout_width="match_parent"
     4     android:layout_height="50dp"
     5     android:paddingLeft="@dimen/activity_horizontal_margin"
     6     android:paddingRight="@dimen/activity_horizontal_margin"
     7     android:orientation="horizontal"  
     8     android:background="#383A37"
     9     >
    10 
    11     <TextView
    12         android:id="@+id/textView1"
    13         android:layout_gravity="center"
    14         android:layout_width="wrap_content"
    15         android:layout_height="wrap_content"
    16         android:textColor="@color/white"
    17         android:textSize="18sp"
    18         android:text="@string/weixin" />
    19 
    20     <TextView
    21         android:id="@+id/textView2"
    22         android:layout_weight="1"
    23         android:layout_width="wrap_content"
    24         android:layout_height="match_parent"
    25         android:text="@string/blank" />
    26     
    27     <LinearLayout
    28         android:layout_width="wrap_content"
    29         android:layout_height="wrap_content" 
    30         android:orientation="horizontal"
    31         android:layout_gravity="center_vertical|center_horizontal">
    32 
    33          <ImageView
    34              android:id="@+id/imageView1"
    35              android:layout_width="30dp"
    36              android:layout_height="30dp"
    37              android:gravity="center_vertical"
    38              android:src="@drawable/fdj" 
    39              android:layout_marginRight="10dp"/>
    40          
    41         <ImageView
    42             android:id="@+id/imageView2"
    43             android:layout_width="30dp"
    44             android:layout_height="30dp"
    45              android:gravity="center_vertical"
    46             android:src="@drawable/barbuttonicon_add"
    47             android:layout_marginRight="10dp" />
    48      </LinearLayout>
    49      
    50 </LinearLayout>
    head.xml
     1 <?xml version="1.0" encoding="utf-8"?>
     2 <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
     3     android:paddingLeft="@dimen/activity_horizontal_margin"
     4     android:paddingRight="@dimen/activity_horizontal_margin"
     5     android:paddingTop="@dimen/activity_horizontal_margin"
     6     android:layout_width="match_parent"
     7     android:layout_height="wrap_content"
     8     android:orientation="horizontal" >
     9 
    10     <RadioGroup
    11         android:id="@+id/radioGroup1"
    12         android:layout_width="match_parent"
    13         android:layout_height="wrap_content" 
    14         android:orientation="horizontal"
    15       >
    16 
    17         <RadioButton
    18             android:id="@+id/radio0"
    19             android:checked="true"
    20             style="@style/radioStyle"
    21             android:drawableTop="@drawable/radio_weixin_check"
    22             android:textColor="@drawable/radio_color_check"
    23             android:text="@string/weixin"  />
    24 
    25         <RadioButton
    26             android:id="@+id/radio1"
    27             style="@style/radioStyle"
    28             android:drawableTop="@drawable/radio_tongxunlu_check"
    29             android:textColor="@drawable/radio_color_check"
    30             android:text="@string/tongxunlu" />
    31 
    32         <RadioButton
    33             android:id="@+id/radio2"
    34             style="@style/radioStyle"
    35             android:drawableTop="@drawable/radio_faxian_check"
    36             android:textColor="@drawable/radio_color_check"
    37             android:text="@string/faxian" />
    38         
    39         <RadioButton
    40             android:id="@+id/radio3"
    41             style="@style/radioStyle"
    42             android:drawableTop="@drawable/radio_wo_check"
    43             android:textColor="@drawable/radio_color_check"
    44             android:text="@string/wo" />
    45     </RadioGroup>
    46 
    47 </LinearLayout>

    下面是微信底部的文件

    1 <?xml version="1.0" encoding="utf-8"?>
    2 <selector xmlns:android="http://schemas.android.com/apk/res/android" >
    3     <item android:state_checked="false"  android:color="#A0A0A0"></item>
    4      <item android:state_checked="true"   android:color="#45C01b"></item>
    5 </selector>
    1 <?xml version="1.0" encoding="utf-8"?>
    2 <selector xmlns:android="http://schemas.android.com/apk/res/android" >
    3      <item android:state_checked="false" android:drawable="@drawable/tabbar_discover"></item>
    4       <item android:state_checked="true" android:drawable="@drawable/tabbar_discoverhl"></item>
    5  </selector>

    后三个同上就不展开了

    1 <?xml version="1.0" encoding="utf-8"?>
    2 <selector xmlns:android="http://schemas.android.com/apk/res/android" >
    3     <item android:state_checked="false" android:drawable="@drawable/tabbar_mainframe"></item>
    4      <item android:state_checked="true" android:drawable="@drawable/tabbar_mainframehl"></item>
    5  </selector>
    radio_weixin_check
    1 <?xml version="1.0" encoding="utf-8"?>
    2 <selector xmlns:android="http://schemas.android.com/apk/res/android" >
    3     <item android:state_checked="false" android:drawable="@drawable/tabbar_me"></item>
    4      <item android:state_checked="true" android:drawable="@drawable/tabbar_mehl"></item>
    5 </selector>
    radio_wo_check
    1 <?xml version="1.0" encoding="utf-8"?>
    2 <selector xmlns:android="http://schemas.android.com/apk/res/android" >
    3      <item android:state_checked="false" android:drawable="@drawable/tabbar_contacts"></item>
    4       <item android:state_checked="true" android:drawable="@drawable/tabbar_contacts_hl"></item>
    5  </selector>
    radio_tongxunlu_check

    mainXML配置

     1 <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
     2     xmlns:tools="http://schemas.android.com/tools"
     3     android:layout_width="match_parent"
     4     android:layout_height="match_parent"
     5     android:orientation="vertical"
     6     tools:context="com.main.weixin.MainActivity" >
     7 
     8     <!-- 头部 -->
     9     <LinearLayout
    10         android:id="@+id/linearLayout1"
    11         android:layout_width="match_parent"
    12         android:layout_height="wrap_content"
    13       >
    14         
    15         <include layout="@layout/head"/>
    16           
    17     </LinearLayout>
    18 
    19     
    20     <!-- 中间 -->
    21     <LinearLayout
    22         android:layout_weight="1"
    23         android:layout_width="match_parent"
    24         android:layout_height="match_parent">
    25         
    26          <include layout = "@layout/listview_layout"></include>
    27         
    28     </LinearLayout>
    29 
    30     
    31     
    32     <!-- 尾部 -->
    33     <LinearLayout
    34         android:layout_width="match_parent"
    35         android:layout_height="wrap_content"
    36       >
    37         
    38         <include layout="@layout/bottom"/>
    39         
    40     </LinearLayout>
    41 </LinearLayout>

    效果如下

  • 相关阅读:
    EM算法
    最大熵模型中的对数似然函数的解释
    PySpark 自定义函数 UDF
    PySpark 自定义聚合函数 UDAF
    Numpy总结
    Examples
    Examples
    Examples
    Examples
    Examples
  • 原文地址:https://www.cnblogs.com/lgk1002/p/6111334.html
Copyright © 2011-2022 走看看