Q:
RadioGroup用途:
RadioButton和CheckBox的区别:
1、单个RadioButton在选中后,通过点击无法变为未选中
单个CheckBox在选中后,通过点击可以变为未选中
2、一组RadioButton,只能同时选中一个
一组CheckBox,能同时选中多个
3、RadioButton在大部分UI框架中默认都以圆形表示
CheckBox在大部分UI框架中默认都以矩形表示
RadioButton和RadioGroup的关系:
1、RadioButton表示单个圆形单选框,而RadioGroup是可以容纳多个RadioButton的容器
2、每个RadioGroup中的RadioButton同时只能有一个被选中
3、不同的RadioGroup中的RadioButton互不相干,即如果组A中有一个选中了,组B中依然可以有一个被选中
4、大部分场合下,一个RadioGroup中至少有2个RadioButton
5、大部分场合下,一个RadioGroup中的RadioButton默认会有一个被选中,并建议您将它放在RadioGroup中的起始位置
首先是布局界面也就是Activity_main.xml它的代码如下:
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent" android:layout_height="match_parent" android:background="@mipmap/skin_bg" android:orientation="vertical" tools:context=".MainActivity"> <!--第一行标题栏--> <TextView android:id="@+id/tv_title" android:layout_width="match_parent" android:layout_height="wrap_content" android:gravity="center" android:text="本地音乐库" android:textSize="25dp" android:textColor="#ffffff"/> <!--线性布局一个--> <LinearLayout android:id="@+id/control_layout" android:layout_width="match_parent" android:layout_height="65dp" android:layout_below="@id/tv_title" android:orientation="horizontal"> <Button android:id="@+id/btn_previous" android:layout_width="0dp" android:layout_height="match_parent" android:gravity="center" android:layout_weight="1" android:background="@mipmap/main_btn_previous" /> <Button android:id="@+id/btn_play_pause" android:layout_width="0dp" android:layout_height="match_parent" android:gravity="center" android:background="@mipmap/main_btn_pause" android:layout_weight="1" /> <!-- android:background="@mipmap/btn_shuffle--> <Button android:id="@+id/btn_next" android:layout_width="0dp" android:layout_height="match_parent" android:gravity="center" android:layout_weight="1" android:background="@mipmap/main_btn_next" /> </LinearLayout> <!--底部控制栏--> <RelativeLayout android:id="@+id/main_bottom_layout" android:layout_width="match_parent" android:layout_height="70dp" android:layout_alignParentBottom="true" android:layout_weight="1" > <LinearLayout android:id="@+id/main_bottom_click" android:layout_width="match_parent" android:layout_height="match_parent" android:layout_toLeftOf="@+id/btn_main_bottom_detail" android:orientation="horizontal"> <ImageView android:id="@+id/main_bottom_image" android:layout_width="wrap_content" android:layout_height="match_parent" android:src="@mipmap/music_bottom" /> <LinearLayout android:id="@+id/main_bottom_v" android:layout_width="wrap_content" android:layout_height="match_parent" android:layout_toRightOf="@+id/main_bottom_image" android:layout_toLeftOf="@+id/btn_main_bottom_detail" android:orientation="vertical" > <TextView android:id="@+id/tv_bottom_title" android:layout_width="wrap_content" android:layout_height="0dp" android:text="音乐的标题" android:textColor="#ffffff" android:layout_weight="1"/> <TextView android:id="@+id/tv_bottom_artist" android:layout_width="wrap_content" android:layout_height="0dp" android:textColor="#ffffff" android:text="音乐的歌手" android:layout_weight="1"/> <LinearLayout android:layout_width="wrap_content" android:layout_height="0dp" android:layout_weight="1" android:orientation="horizontal"> <TextView android:id="@+id/tv_bottom_currentTime" android:layout_width="wrap_content" android:layout_height="match_parent" android:text="当前时间" android:textColor="#ffffff" android:layout_weight="1"/> <TextView android:id="@+id/tv_botton_durationTime" android:layout_width="wrap_content" android:layout_height="match_parent" android:layout_marginLeft="10dp" android:textColor="#ffffff" android:text="总时间" /> </LinearLayout> </LinearLayout> </LinearLayout> <Button android:id="@+id/btn_main_bottom_detail" android:layout_width="wrap_content" android:layout_height="match_parent" android:text="详细信息" android:textColor="#ffffff" android:layout_alignParentRight="true" /> </RelativeLayout> <ListView android:id="@+id/lv_musicList" android:layout_width="match_parent" android:layout_height="match_parent" android:focusable="true" android:layout_below="@+id/control_layout" android:layout_above="@+id/main_bottom_layout" > </ListView> </RelativeLayout>