Android利用利用GridView实现单选效果实现单选效果
本篇文章主要介绍了Android利用GridView实现单选效果的相关知识,具有很好的参考价值。下面跟着小编一起
来看下吧
1.实现如图所示的单选效果实现如图所示的单选效果
由于Android提供的单选按钮radiobutton只能单行或单列显示,且样式并不美观,故可用GridView进行改造,实现单选效果,
而要实现这样的效果重点就在GridView的适配器这块了。
首先是首先是GridView的的item的的XML::
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent">
<RelativeLayout
android:id="@+id/options"
android:layout_width="match_parent"
android:layout_height="143dp">
<ImageView
android:id="@+id/imageView"
android:layout_width="65dp"
android:layout_height="65dp"/>
<TextView
android:id="@+id/textView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerInParent="true"
android:text="通讯录"/>
</RelativeLayout>
</LinearLayout>