最近写了个小demo,仿京东的分类功能实现,网上看了有些用ListView并排,个人并不推荐这种方法,自己使用ListView+Fragment实现,OK,直接上代码
首先看主页面布局
<?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:orientation="horizontal" android:layout_height="match_parent"> <LinearLayout android:layout_width="match_parent" android:layout_height="match_parent" android:background="#EAE8E9" android:orientation="horizontal" > <ListView android:id="@+id/listview" android:layout_width="0dp" android:layout_height="wrap_content" android:scrollbars="none" android:layout_weight="1.0" android:background="@color/whilte" /> <FrameLayout android:id="@+id/fragment_container" android:layout_marginLeft="10dp" android:layout_width="0dp" android:background="@color/whilte" android:layout_height="match_parent" android:layout_weight="3.0" /> </LinearLayout> </LinearLayout>左边使用ListVIew,右边使用FramLayout。接着往下看页面代码: