其实做法很简单就是在你的listview的外部加一个HorizontalScrollView就行了
main.xml如下
<RelativeLayout 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" >
<HorizontalScrollView
android:id="@+id/horizontalScrollView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentTop="true">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="horizontal" >
<ListView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="@+id/listview"></ListView>
</LinearLayout>
</HorizontalScrollView>
</RelativeLayout>
activity.java如下
public class FirstListView extends Activity {
private ListView lv;
private List<String> items=new ArrayList<String>();
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main2);
lv=(ListView)findViewById(R.id.listview);
for (int i = 0; i < 20; i++) {
items.add("fengluchun"+i);
}
lv.setAdapter(new MyAdapter());
}
class MyAdapter extends BaseAdapter{
@Override
public int getCount() {
return items.size();
}
@Override
public Object getItem(int position) {
return null;
}
@Override
public long getItemId(int position) {
return 0;
}
LayoutInflater inflater=LayoutInflater.from(FirstListView.this);
@Override
public View getView(int position, View convertView, ViewGroup parent) {
View view=null;
if (convertView==null) {
view=inflater.inflate(R.layout.listformat, null);
}else {
view=convertView;
}
TextView tv1=(TextView)view.findViewById(R.id.textView1);
TextView tv2=(TextView)view.findViewById(R.id.textView2);
TextView tv3=(TextView)view.findViewById(R.id.textView3);
tv1.setText(items.get(position));
tv2.setText(items.get(position));
tv3.setText(items.get(position));
return view;
}
}
}
你可以试试哦!
来源:oschina
链接:https://my.oschina.net/u/114929/blog/70680