我正试图做到这一点,
我做的是
我在HorizontalScrollView
中尝试了ListView
但是无法正确获取。
任何帮助将不胜感激。
这是我的xml
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_weight="8"
android:orientation="vertical">
<com.android.ViewPagerContainer
android:id="@+id/container"
android:layout_width="wrap_content"
android:layout_height="fill_parent">
<android.support.v4.view.ViewPager
android:id="@+id/viewpager"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
</com.android.ViewPagerContainer>
</LinearLayout>
我的密码是
private class ViewAdapter extends PagerAdapter {
private int count = values.size();
@Override
public int getCount() {
return count;
}
public void setCount(int count) {
this.count = count;
}
@Override
public boolean isViewFromObject(View view, Object object) {
return (view == object);
}
@Override
public LinearLayout instantiateItem(ViewGroup container, int position) {
LinearLayout llViewOuter = new LinearLayout(getActivity());
llViewOuter.setOrientation(LinearLayout.VERTICAL);
ImageView thumb_image = new ImageView(getActivity());
thumb_image.setImageResource(R.drawable.optionnor);
thumb_image.setScaleType(ImageView.ScaleType.FIT_CENTER);
llViewOuter.addView(thumb_image);
TextView tmpT = new TextView(getActivity());
tmpT.setText(values.get(position));
tmpT.setGravity(Gravity.CENTER);
llViewOuter.addView(tmpT);
final ImageView checkBox = new ImageView(getActivity());
checkBox.setImageResource(R.drawable.optionnor);
checkBox.setAdjustViewBounds(true);
checkBox.setScaleType(ImageView.ScaleType.FIT_CENTER);
checkBox.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
//checkbox2.setImageResource(R.drawable.option);
checkBox.setImageResource(R.drawable.optionselected);
}
});
llViewOuter.addView(checkBox);
((ViewPager) container).addView(llViewOuter);
return llViewOuter;
}
@Override
public void destroyItem(ViewGroup container, int position, Object object) {
((ViewPager) container).removeView((LinearLayout) object);
}
}
最佳答案
您可以使用此水平ListView库https://github.com/EmirWeb/parchment。
public class ListView<ADAPTER extends Adapter> extends AbstractAdapterView<ADAPTER,View>
implements OnLongClickListener, OnClickListener,
OnSelectedListener, AdapterViewHandler {
public ListView(final Context context) {
super(context);
}
public ListView(final Context context, final AttributeSet attributeSet) {
super(context, attributeSet);
}
public ListView(final Context context, final AttributeSet attributeSet, final int defStyle) {
super(context, attributeSet, defStyle);
}
@Override
protected AdapterViewInitializer<View> getAdapterViewInitializer(final Context context, final AttributeSet attributeSet) {
final Attributes attributes = new Attributes(context, attributeSet);
final boolean isViewPager = attributes.isViewPager();
final boolean isVerticalScroll = attributes.isVertical();
final int cellSpacing = (int) attributes.getCellSpacing();
final boolean isCircularScroll = attributes.isCircularScroll();
final boolean snapToPosition = attributes.isSnapToPosition();
final int viewPagerInterval = attributes.getViewPagerInterval();
final SnapPosition snapPosition = attributes.getSnapPosition();
final boolean selectOnSnap = attributes.selectOnSnap();
final boolean selectWhileScrolling = attributes.selectWhileScrolling();
final LayoutManagerAttributes layoutManagerAttributes = new LayoutManagerAttributes(isCircularScroll, snapToPosition, isViewPager, viewPagerInterval, snapPosition, cellSpacing, selectOnSnap, selectWhileScrolling, isVerticalScroll);
final AdapterViewManager adapterViewManager = new AdapterViewManager();
final ListLayoutManager listLayoutManager = new ListLayoutManager(this, this, adapterViewManager, layoutManagerAttributes);
final AdapterViewInitializer<View> adapterViewAdapterViewInitializer = createAdapterViewInitializer(context, isViewPager, adapterViewManager, listLayoutManager, isVerticalScroll);
return adapterViewAdapterViewInitializer;
}
}
希望你喜欢。