Android中的RadioButton必须直接以RadioGroup为父组件才能发挥作用,而RadioGroup只能设置”横向”和”纵向”。
在pad开发中,因为屏幕比较开阔,因此,对于一些单项选择,其实做成GridView样式更美观。
在Android4.0以上的API中,提供了GridLayout这个布局,可以实现网格布局,以一个银行选择弹出框为例,记个小笔记。
效果如下:
点击左上角的其他银行,弹出AlertDialog,并动态的添加了银行数组内所有银行的信息。单选按钮其实是imageview,点击确定后,被选中的银行信息会显示在界面上,dialog也会推出,当下次再弹出dialog时,默认被选中的条目将是当前界面显示银行条目。
布局:
activity_main.xml
<LinearLayout 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" >
<Button
android:id="@+id/btn_card"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="其他银行" />
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="horizontal" >
<ImageView
android:id="@+id/iv_logo"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
<TextView