Pupkin Vasja
- Forum posts: 1
Jul 3, 2012, 2:02:38 PM via Website
Jul 3, 2012 2:02:38 PM via Website
I've got a ViewPager and a TextView inside it. When content of TextView is larger then it is visible on screen, there shall be possibility to scroll it vertically. But it does not do this automatically
Here is an xml for TextView
Here is an xml for TextView
1<?xml version="1.0" encoding="utf-8"?>
2 <TextView xmlns:android="http://schemas.android.com/apk/res/android"
3 android:id="@+id/txText"
4 android:layout_width="fill_parent"
5 android:layout_height="wrap_content"
6 android:background="#338877"
7 android:padding="15dp"
8 android:scrollHorizontally="false"
9 android:scrollbarAlwaysDrawVerticalTrack="true"
10 android:scrollbars="vertical"
11 android:textAppearance="?android:attr/textAppearanceMedium" />
And here is an xml for ViewPager2 <TextView xmlns:android="http://schemas.android.com/apk/res/android"
3 android:id="@+id/txText"
4 android:layout_width="fill_parent"
5 android:layout_height="wrap_content"
6 android:background="#338877"
7 android:padding="15dp"
8 android:scrollHorizontally="false"
9 android:scrollbarAlwaysDrawVerticalTrack="true"
10 android:scrollbars="vertical"
11 android:textAppearance="?android:attr/textAppearanceMedium" />
1<?xml version="1.0" encoding="utf-8"?>
2<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
3 android:id="@+id/RelativeLayout1"
4 android:layout_width="fill_parent"
5 android:layout_height="fill_parent"
6 android:orientation="vertical" >
7
8 <android.support.v4.view.ViewPager
9 android:id="@+id/vpPonkSwiper"
10 android:layout_width="fill_parent"
11 android:layout_height="fill_parent"
12 android:layout_above="@+id/lbPonkFooter" />
13
14 <TextView
15 android:id="@+id/lbPonkFooter"
16 android:layout_width="fill_parent"
17 android:layout_height="30dp"
18 android:layout_alignParentBottom="true"
19 android:layout_alignParentLeft="true"
20 android:text="Footer" />
21
22</RelativeLayout>
Here is an Adapter:2<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
3 android:id="@+id/RelativeLayout1"
4 android:layout_width="fill_parent"
5 android:layout_height="fill_parent"
6 android:orientation="vertical" >
7
8 <android.support.v4.view.ViewPager
9 android:id="@+id/vpPonkSwiper"
10 android:layout_width="fill_parent"
11 android:layout_height="fill_parent"
12 android:layout_above="@+id/lbPonkFooter" />
13
14 <TextView
15 android:id="@+id/lbPonkFooter"
16 android:layout_width="fill_parent"
17 android:layout_height="30dp"
18 android:layout_alignParentBottom="true"
19 android:layout_alignParentLeft="true"
20 android:text="Footer" />
21
22</RelativeLayout>
1public class PonkPageAdapter extends PagerAdapter
2{
3 private int pagesCount = -1;
4 private List<Ponk> data;
5 private App app;
6 private MockPersistence db;
7 private Activity activity;
8 private TextView currentView;
9 private LayoutInflater inflater;
10
11 public PonkPageAdapter(Activity activity, byte section) {
12 this.activity = activity;
13 this.app = ((App) activity.getApplication());
14 this.db = app.getPersistence();
15 this.section = section;
16 this.data = db.findPonksBySection(section); // new LinkedList<Ponk>();
17 this.inflater = (LayoutInflater) activity.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
18 //
19 this.pagesCount = db.countPonksInSection(section);
20 }
21
22 @Override
23 public int getCount()
24 {
25 return pagesCount;
26 }
27
28 @Override
29 public Object instantiateItem(View collection, int position)
30 {
31 TextView tv = getNewView();
32 Ponk j = data.get(position);
33 tv.setText(j.text);
34 tv.setTag(j.id);
35 setFontSizeInSP(tv, app.getFontSize());
36 tv.setTag(position);
37 ((ViewPager) collection).addView(tv, 0);
38
39 return tv;
40 }
41
42 private TextView getNewView()
43 {
44 LayoutInflater inflater = (LayoutInflater) activity.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
45 TextView tv = (TextView)inflater.inflate(R.layout.Ponk, null);
46 return tv;
47 }
48
49 @Override
50 public void setPrimaryItem(ViewGroup container, int position, Object object)
51 {
52 currentView = (TextView) object;
53 }
54
55 @Override
56 public void destroyItem(View collection, int position, Object view)
57 {
58 ((ViewPager) collection).removeView((TextView) view);
59 }
60
61 @Override
62 public boolean isViewFromObject(View view, Object object)
63 {
64 return view == (TextView) object;
65 }
66
67 @Override
68 public Parcelable saveState()
69 {
70 return null;
71 }
72}
2{
3 private int pagesCount = -1;
4 private List<Ponk> data;
5 private App app;
6 private MockPersistence db;
7 private Activity activity;
8 private TextView currentView;
9 private LayoutInflater inflater;
10
11 public PonkPageAdapter(Activity activity, byte section) {
12 this.activity = activity;
13 this.app = ((App) activity.getApplication());
14 this.db = app.getPersistence();
15 this.section = section;
16 this.data = db.findPonksBySection(section); // new LinkedList<Ponk>();
17 this.inflater = (LayoutInflater) activity.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
18 //
19 this.pagesCount = db.countPonksInSection(section);
20 }
21
22 @Override
23 public int getCount()
24 {
25 return pagesCount;
26 }
27
28 @Override
29 public Object instantiateItem(View collection, int position)
30 {
31 TextView tv = getNewView();
32 Ponk j = data.get(position);
33 tv.setText(j.text);
34 tv.setTag(j.id);
35 setFontSizeInSP(tv, app.getFontSize());
36 tv.setTag(position);
37 ((ViewPager) collection).addView(tv, 0);
38
39 return tv;
40 }
41
42 private TextView getNewView()
43 {
44 LayoutInflater inflater = (LayoutInflater) activity.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
45 TextView tv = (TextView)inflater.inflate(R.layout.Ponk, null);
46 return tv;
47 }
48
49 @Override
50 public void setPrimaryItem(ViewGroup container, int position, Object object)
51 {
52 currentView = (TextView) object;
53 }
54
55 @Override
56 public void destroyItem(View collection, int position, Object view)
57 {
58 ((ViewPager) collection).removeView((TextView) view);
59 }
60
61 @Override
62 public boolean isViewFromObject(View view, Object object)
63 {
64 return view == (TextView) object;
65 }
66
67 @Override
68 public Parcelable saveState()
69 {
70 return null;
71 }
72}
Recommended editorial content
With your consent, external content is loaded here.
By clicking on the button above, you agree that external content may be displayed to you. Personal data may be transmitted to third-party providers in the process. You can find more information about this in our Privacy Policy.