前段时间在项目开发中,有listview实现单选和多选的效果,特别是listview的单选效果,一开始项目比较紧,自己考虑的是用列表视图和radionbutton实现的,可能是自己考虑不周到的原因,效果是实现了,但是用户体验不怎么好,做完项目后,自己又弄了下,使用列表视图和imageview实现,点击listview条目的时候就可以实现单选效果,这样用户体验就稍微好些。以下就是实现的方式:
activity_main.xml文件:
& lt; RelativeLayout xmlns: android=" http://schemas.android.com/apk/res/android " xmlns:工具=" http://schemas.android.com/tools " android: layout_width=" match_parent " android: layout_height=" match_parent " 工具:上下文=" com.listtest。祝辞MainActivity PlaceholderFragment美元”; & lt;列表视图 android: id=癅 + id/视图” android: layout_width="宽和" android: layout_height="宽和"/比; & lt;/RelativeLayout> >之前listview_item.xml文件
& lt; RelativeLayout xmlns: android=" http://schemas.android.com/apk/res/android " xmlns:工具=" http://schemas.android.com/tools " android: layout_width=" match_parent " android: layout_height=" match_parent " 工具:上下文=" com.listtest。祝辞MainActivity PlaceholderFragment美元”; & lt;使用 android: layout_width="宽和" android: layout_height=" 50 dp”比; & lt; TextView android: id=癅 + id/电视” android: layout_width=" wrap_content " android: layout_height=" wrap_content " android: textSize=" 15 sp” android:输入textColor=" # 000000 " android:文本=" 123112 " android: layout_centerVertical=" true " android: layout_marginLeft=?5 dp/比; & lt; ImageView android: id=癅 + id/iv” android: layout_width=" wrap_content " android: layout_height=" wrap_content " android: src=" https://www.yisu.com/zixun/@drawable sex_nor " android: layout_alignParentRight=" true " android: layout_centerVertical=" true " android: layout_marginRight=?5 dp/比; & lt;/RelativeLayout> & lt;/RelativeLayout> >之前MainActivity文件:
公共类MainActivity ActionBarActivity延伸实现alt=" Android中列表视图和imageview实现条目单选效果">以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持。
Android中列表视图和imageview实现条目单选效果