2012-07-01 45 views
1

我在裏面有一個ViewPager和一個TextView。當TextView的內容較大時,它在屏幕上可見,則可以垂直滾動它。但它不會自動執行此操作:(如何使ViewPager內的TextView垂直滾動

這裏是的TextView

<?xml version="1.0" encoding="utf-8"?> 
    <TextView xmlns:android="http://schemas.android.com/apk/res/android" 
     android:id="@+id/txText" 
     android:layout_width="fill_parent" 
     android:layout_height="wrap_content" 
     android:background="#338877" 
     android:padding="15dp" 
     android:scrollHorizontally="false" 
     android:scrollbarAlwaysDrawVerticalTrack="true" 
     android:scrollbars="vertical" 
     android:textAppearance="?android:attr/textAppearanceMedium" /> 

的XML和這裏是一個XML ViewPager

<?xml version="1.0" encoding="utf-8"?> 
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:id="@+id/RelativeLayout1" 
    android:layout_width="fill_parent" 
    android:layout_height="fill_parent" 
    android:orientation="vertical" > 

    <android.support.v4.view.ViewPager 
     android:id="@+id/vpPonkSwiper" 
     android:layout_width="fill_parent" 
     android:layout_height="fill_parent" 
     android:layout_above="@+id/lbPonkFooter" /> 

    <TextView 
     android:id="@+id/lbPonkFooter" 
     android:layout_width="fill_parent" 
     android:layout_height="30dp" 
     android:layout_alignParentBottom="true" 
     android:layout_alignParentLeft="true" 
     android:text="Footer" /> 

</RelativeLayout> 

這裏是一個適配器:

public class PonkPageAdapter extends PagerAdapter 
{ 
    private int    pagesCount = -1; 
    private List<Ponk>  data; 
    private App    app; 
    private MockPersistence db; 
    private Activity  activity; 
    private TextView  currentView; 
    private LayoutInflater inflater; 

    public PonkPageAdapter(Activity activity, byte section) { 
     this.activity = activity; 
     this.app = ((App) activity.getApplication()); 
     this.db = app.getPersistence(); 
     this.section = section; 
     this.data = db.findPonksBySection(section); // new LinkedList<Ponk>(); 
     this.inflater = (LayoutInflater) activity.getSystemService(Context.LAYOUT_INFLATER_SERVICE); 
     // 
     this.pagesCount = db.countPonksInSection(section); 
    } 

    @Override 
    public int getCount() 
    { 
     return pagesCount; 
    } 

    @Override 
    public Object instantiateItem(View collection, int position) 
    { 
     TextView tv = getNewView(); 
     Ponk j = data.get(position); 
     tv.setText(j.text); 
     tv.setTag(j.id); 
     setFontSizeInSP(tv, app.getFontSize()); 
     tv.setTag(position); 
     ((ViewPager) collection).addView(tv, 0); 

     return tv; 
    } 

    private TextView getNewView() 
    { 
     LayoutInflater inflater = (LayoutInflater) activity.getSystemService(Context.LAYOUT_INFLATER_SERVICE); 
     TextView tv = (TextView)inflater.inflate(R.layout.Ponk, null); 
     return tv; 
    } 

    @Override 
    public void setPrimaryItem(ViewGroup container, int position, Object object) 
    { 
     currentView = (TextView) object; 
    } 

    @Override 
    public void destroyItem(View collection, int position, Object view) 
    { 
     ((ViewPager) collection).removeView((TextView) view); 
    } 

    @Override 
    public boolean isViewFromObject(View view, Object object) 
    { 
     return view == (TextView) object; 
    } 

    @Override 
    public Parcelable saveState() 
    { 
     return null; 
    } 
} 
+0

你所示的'RelativeLayout'以'ViewPager'和'TextView'在它與一個'TextView'一個separaye佈局文件,但無處有什麼哪顯示在'ViewPager'內部使用單獨的'TextView'。 – Squonk

+0

我已更新主帖 –

+0

檢查了兄弟,看看是否有幫助http://stackoverflow.com/questions/22617951/scrollable-textview-in-viewpager –

回答

0

嘗試在來包裝你TextView一個ScrollView

<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"> 
    <TextView 
     android:layout_width="fill_parent" 
     android:layout_height="wrap_content" 
... 
+0

不起作用 - 我認爲問題是與事件傳播 –