问题 1 - 也许您应该重新考虑您的设计以使用HorizonzalListView列表。
问题 2 - 您可以通过编程方式创建 HorizontialListView 列表,将它们放置在由垂直滚动视图包裹的 LinearLayout 中。
您的 myhlist.xml 布局:
<?xml version="1.0" encoding="utf-8"?>
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<LinearLayout android:id="@+id/list_of_hlist_placeholder"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_gravity="center_horizontal"/>
</ScrollView>
你的活动:
public class ListOfHListlActivity extends Activity {
/** List of ArrayAdapter with each bind to a HorizontialListView created programmatically */
private List<MyAdapter> myAdapters = new ArrayList<MyAdapter>();
/** List of your data model */
private List<Object> myDataList;
/**
* Worker thread running in background doing dirty job.
*/
private class DoDirtyJobAsyncTask extends AsyncTask<Void, MyAdapter, Void> {
@Override
protected Void doInBackground(Void... params) {
// do your dirty job here, to populate myDataList
for (Object myData : myDataList) {
MyAdapter myAdapter = new MyAdapter(myData);
myAdapters.add(myAdapter);
publishProgress(myAdapter);
}
return null;
}
@Override
protected void onProgressUpdate(MyAdapter... myAdapters) {
int currViewId = 1;
for (final MyAdapter myAdapter: myAdapters) {
HorizontialListView listview = new HorizontialListView(getApplicationContext(), null);
listview.setId(currViewId);
listview.setAdapter(myAdapter);
listview.setOnItemClickListener(new OnItemClickListener() {
public void onItemClick(AdapterView<?> parent, View v, int position, long id) {
// I am clickable.
}
});
RelativeLayout listOfHListLayout = (RelativeLayout) findViewById(R.id.list_of_hlist_placeholder);
// don't forget set height here, you know the height issue in HorizontialListView
RelativeLayout.LayoutParams layoutParams = new RelativeLayout.LayoutParams(
RelativeLayout.LayoutParams.FILL_PARENT, 40);
listOfHListLayout.addView(listview, layoutParams);
currViewId++;
}
}
}
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
new DoDirtyJobAsyncTask().execute();
setContentView(R.layout.myhlist);
}
}