I have a list view with 20 rows and I want to setup a horizontal scrollview
for every row item in list view, as each row contains more than one item.
Here is my code :
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="horizontal" >
<HorizontalScrollView
android:id="@+id/hor_scroll"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:scrollbars="none" >
<LinearLayout
android:id="@+id/mainLinear"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="horizontal" >
</LinearLayout>
</HorizontalScrollView>
</RelativeLayout>
Inner Row Layout which is to be replicated in a row any number of times
<ImageView
android:id="@+id/icon"
android:layout_width="wrap_content"
android:layout_height="fill_parent"
android:layout_marginRight="6.0dip"
android:src="@drawable/ic_launcher" />
<TextView
android:id="@+id/text"
android:layout_width="wrap_content"
android:layout_height="fill_parent"
android:gravity="center_vertical"
android:text="Example Value"
android:textAppearance="?android:textAppearanceMedium" />
BaseAdapter
public class HorizontalListViewAdapter extends BaseAdapter {
private Context context;
private ArrayList<ArrayList<DwivediJi>> dataSet;
public HorizontalListViewAdapter(Context context) {
this.context = context;
}
@Override
public int getCount() {
return 20;
}
@Override
public Object getItem(int arg0) {
// TODO Auto-generated method stub
return arg0;
}
@Override
public long getItemId(int arg0) {
// TODO Auto-generated method stub
return arg0;
}
@Override
public View getView(int position, View convertView, ViewGroup parent) {
LayoutInflater inflater = (LayoutInflater)context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
convertView = inflater.inflate(R.layout.horizontal_list_item, null,false);
LinearLayout mainLinnerLayout=(LinearLayout)convertView.findViewById(R.id.mainLinear);
for (int i = 0; i <5; i++) {
View additionView = inflater.inflate(R.layout.inner_layout_file, null,false);
LinearLayout innerLinnerLayout=(LinearLayout)additionView.findViewById(R.id.inner_layout);
mainLinnerLayout.addView(innerLinnerLayout);
}
return convertView;
}
class ViewHolder {
TextView tv_titleExample;
HorizontalScrollView hzView;
LinearLayout linear_layout,main_linear_layout;
}
}
My Problem
Look at the screenshot attached. My problem is that more than one view is showing at one time in each row.
I want that only one view should show to the user at one time and for the rest all the user has to do is swipe left to right or right to left.
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…