问题
I would like to create a horizontally scrolling view of an image with text description and a button.
Each entry in the list will take up the entire screen with a picture on the left and some descriptive text to the right of that. Scrolling left or right will move the entire view one screen along and display the next picture and text.
What is the best way to display such data?
Thanks, M
回答1:
You may need to check out the ViewFlipper of android.
回答2:
I think you are in search of listview which can be explored horizontally rather than vertically.
so you can take a look at horizontal listview code of course you can use gallery for this type of view.... Hope this may help you... Have a Happy coding.
回答3:
OK, here is a way to implement what I was looking to do. I initially took this from http://geekyouup.blogspot.com/2011/07/viewpager-example-from-paug.html but I wanted to add more than one textView to the scrolling list.
I was struggling at first to include more than the one text view which is shown in the demo at this site but it was because of then Casting to TextView in the destroyItem and initemfromObject methods. I'm going to be writing a PagerCurrsor adapter for sqlite so I'll post it here when I get it working.
Another thing to note is that position is incremented as the user swipes through the list so you would use that to iterate through an array or a cursor.
Hope this helps other developers and thanks for all the answers posted.
Overidden methods:
public Object instantiateItem(View collection, int position) {
layout = inflater.inflate(R.layout.scrolllayout, null);
TextView tv = (TextView) layout.findViewById(R.id.textView1);
tv.setText("1________________>" + position);
TextView tv2 = (TextView) layout.findViewById(R.id.textView2);
tv.setText("2________________>" + position);
((ViewPager) collection).addView(layout);
return layout;
}
@Override
public void destroyItem(View collection, int position, Object view) {
((ViewPager) collection).removeView((View)view);
}
@Override
public boolean isViewFromObject(View view, Object object) {
return view==((View)object);
}
XML:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:id= "@+id/container"
android:layout_width="match_parent"
android:layout_height="match_parent" android:orientation="vertical">
<TextView android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="TextView1" android:id="@+id/textView1"></TextView>
<TextView android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="TextView2" android:id="@+id/textView2"></TextView>
</LinearLayout>
[1]http://geekyouup.blogspot.com/2011/07/viewpager-example-from-paug.html
来源:https://stackoverflow.com/questions/7256089/displaying-horizontal-scrolling-view-of-a-linear-layout