2011-08-29 208 views
3

基本上我有一個水平滾動視圖,通過監視onTouch事件我正在分頁(即:滾動視圖(頁面)的每個可見部分「點擊」滾動到下一個,而不僅僅是具有標準的ScrollView。請參閱iOS中的分頁滾動視圖)。horizo​​ntalscrollview設置子元素來填充horizo​​ntalscrollview的寬度

現在我想找到一種方法來讓內部子代繼承與滾動視圖相同的寬度(設置爲"fill_parent")。

這裏是我的XML的幫助:

<HorizontalScrollView 
     android:id="@+id/scrollview" 
     android:layout_height="0dp" 
     android:layout_width="fill_parent" 
     android:layout_weight="1" 
     android:background="@drawable/scrollviewbg"> 

     <LinearLayout 
      android:orientation="horizontal" 
      android:layout_width="wrap_content" 
      android:layout_height="fill_parent"> 

      <ImageView 
       android:src="@drawable/content1" 
       android:layout_width="wrap_content" 
       android:layout_height="wrap_content" /> 
      <ImageView 
       android:src="@drawable/content2" 
       android:layout_width="wrap_content" 
       android:layout_height="wrap_content" /> 
      <ImageView 
       android:src="@drawable/content3" 
       android:layout_width="wrap_content" 
       android:layout_height="wrap_content" /> 

     </LinearLayout> 

    </HorizontalScrollView> 

正如你可以看到滾動視圖設置爲寬度fill_parent並且裏面有它LinearLayout。現在有三個圖像的寬度和高度與屏幕寬度相似,但我想要做的是更改爲3 LinearLayout s。

每個LinearLayout都需要繼承與滾動視圖相同的寬度,這樣當我的代碼被應用時,每個代碼都會佔用整個「頁面」。

我該怎麼做?這是我將不得不使用代碼嗎?我需要什麼代碼?

謝謝。

回答

3

我知道它沒有直接的答案,但對於尋呼功能來說,它更容易從Compatibility Package用戶ViewPager。您可以在samples文件夾中找到示例(有關源代碼,請參閱src/com/example/android/supportv4/app/FragmentPagerSupport.java)。

+0

是容易得多。感謝那。 :) –

+0

我沒有該選項使用支持庫,我們可以在scrollview中執行 – user606669

0

將所有layout_height參數設置爲fill_parent。你應該在全屏幕中看到圖像。

+1

錯誤!當將子視圖添加到「Horizo​​ntalScrollView」時,「fill_parent」沒有意義。 – neevek

0

試試這個: 機器人:fillViewport = 「真」

<HorizontalScrollView 

    android:fillViewport="true" 

    android:layout_width="match_parent" 
    android:layout_height="wrap_content"> 
<TextView 
    android:layout_gravity="right" 
    android:background="@drawable/black_border" 
    android:id="@+id/displayText" 
    android:layout_width="match_parent" 
    android:scrollHorizontally="true" 
    android:layout_height="wrap_content" 
    android:gravity="right" 
    android:padding="20dp" 
    android:text="" 
    android:textSize="20sp" /> 
</HorizontalScrollView> 

水平滾動視圖中,我有一個文本視圖,你可以嘗試圖像視圖

相關問題