2014-01-23 95 views
2

這是我的HorizontalScrollView的Android Horizo​​ntalScrollView寬度

<HorizontalScrollView 
    android:id="@+id/horizontalScrollView1" 
    android:layout_width="match_parent" 
    android:layout_height="0dp" 
    android:layout_weight="19" > 

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

     <RelativeLayout 
      android:layout_width="match_parent" 
      android:layout_height="match_parent" 
      android:background="@drawable/card_background" > 

     </RelativeLayout> 

    </LinearLayout> 
</HorizontalScrollView> 

我想設置的RelativeLayout的等於Horizo​​ntalScrollView的寬度寬XML。我怎樣才能做到這一點與XML(不是編程)

+0

集的RelativeLayout父母的LinearLayout寬度match_parent ... –

回答

1

我會定義你想要設置爲RelativeLayout的寬度,並將HorizontalScrollView的寬度和高度設置爲wrap_content。這樣,它不是定義寬度的HorizontalScrollView,它只是包裹它。

+0

我希望我的RelativeLayout採取屏幕的全部寬度。在這種情況下,我不能將它設置爲match_parent,因爲我的RelativeLayout的父母是一個LinearLayout – user3199577

+0

然後,我將在Horizo​​ntalScrollView上方添加另一個RelativeLayout,將其寬度設置爲match_parent,然後聲明Horizo​​ntalScrollView的寬度設置爲wrap_content,this方式你知道它將是所有的寬度和長卷軸將包裝它的一切。 – nKn

8

所有你缺少你想要的東西是在Horizo​​ntalScrollView

android:fillViewport="true" 
+0

它沒有改變任何東西,因爲我在我的scrollview中有一個線性佈局,它具有'width =「wrap_content」' – user3199577

+0

沒有佈局的其餘部分我唯一的問題是沒有fillViewport設置的唯一問題是0dp,因爲我測試horizo​​ntalScrollView具有根元素。如果您將0dp更改爲match_parent,則會填充整個屏幕。 也許如果你提供德整個佈局,我們可以進一步幫助... – Mikel

+0

現在它工作正常,但又出現了另一個問題。當我添加視圖到我的ScrollView時,我可以正常滾動 – user3199577

相關問題