电子产品的网站建设,做一个简单的网页游戏,网站内链建设和外链的推广,网站建设的功能要求前言 前面在适配器章节#xff0c;已经介绍了ListView的作用(干什么的)#xff0c;这节将主要介绍如何去设计ListView页面视图。 思考 列表视图需要些什么#xff1f; 1. 列表项容器#xff08;装载各列表项的容器#xff09;#xff1a;ListView/ 2. 列表项布局…前言 前面在适配器章节已经介绍了ListView的作用(干什么的)这节将主要介绍如何去设计ListView页面视图。 思考 列表视图需要些什么 1. 列表项容器装载各列表项的容器ListView/ 2. 列表项布局my_list_item.xml 3. 列表所需数据ListObject、Adapter(桥梁) 代码示例 下面的代码示例是从我的项目中copy的是一个很好的例子 // 1. 列表项容器activity_charge_up.xml(仅展示了相关部分)
ListViewandroid:idid/cuisine_listandroid:layout_widthmatch_parentandroid:layout_heightmatch_parent
/ListView// 2. 列表项布局cuisine_list_item.xml
?xml version1.0 encodingutf-8?
RelativeLayout xmlns:androidhttp://schemas.android.com/apk/res/androidandroid:layout_widthmatch_parentandroid:layout_heightmatch_parentRelativeLayoutandroid:layout_widthmatch_parentandroid:layout_height60dpandroid:background#FEFCEBandroid:layout_margin10dpTextViewandroid:idid/cuisineNameandroid:layout_width75dpandroid:layout_heightwrap_contentandroid:layout_centerVerticaltrueandroid:layout_marginLeft20dpandroid:text西红柿炒鸡蛋android:textColorcolor/blackandroid:textSize12sp/TextViewTextViewandroid:idid/cuisinePriceandroid:layout_widthwrap_contentandroid:layout_heightwrap_contentandroid:layout_centerVerticaltrueandroid:layout_marginLeft5dpandroid:layout_toRightOfid/cuisineNameandroid:text99.90android:textColor#FF1100android:textSize12spandroid:textStylebold/TextViewButtonandroid:idid/subCuisineandroid:layout_width30dpandroid:layout_height30dpandroid:layout_centerVerticaltrueandroid:layout_toLeftOfid/cuisineQuantityandroid:textSize5dpandroid:backgrounddrawable/sub/ButtonTextViewandroid:idid/cuisineQuantityandroid:layout_width20dpandroid:layout_heightwrap_contentandroid:layout_centerVerticaltrueandroid:layout_toLeftOfid/addCuisineandroid:gravitycenterandroid:text0android:textColorcolor/blackandroid:textSize10dp/TextViewButtonandroid:idid/addCuisineandroid:layout_width30dpandroid:layout_height30dpandroid:backgrounddrawable/addandroid:layout_alignParentRighttrueandroid:layout_centerVerticaltrueandroid:textSize5sp/Button/RelativeLayout
/RelativeLayout适配器的使用很简单 MyAdapter myAdapter new MyAdapter(参数);
ListView cuisineList findById(R.layout.cuisine_list);
cuisineList.setAdapter(myAdapter); 复杂的是适配器的业务逻辑(适配器的实现) 对于适配器的实现可以参考前面适配器章节这里就不再做具体的代码示例。 在实际需求中在适配器中你可能需要接受多个参数你需要处理列表项的交互譬如点击你可能也需要即时地去改变列表项所在页面的相关控件内容因为修改列表项一般也需要修改其他页面元素。 导航栏 其实学习ListView后当想到设计导航栏后可能会想到它能否胜任导航栏的设计呢 并不好去设计。首先导航栏不仅有竖直的还有水平的其二导航栏不仅仅是导航栏的变化更涉及到导航内容的变化。 所以导航栏的设计一般有以下两种策略 (1) 自己设计导航(LinearLayout)、导航页面内容(removeAllViewsaddViewLayoutInflater) (2) 可用控件Fragment、ViewPager参考链接Android四种底部导航栏实现 后言 下一节将介绍RecyclerView的相关知识