0

的高度尺寸我有內部的LinearLayout一堆的RelativeLayout的。這裏面會有ProgressBar和其他元素。Android的進度正在改變父母的LinearLayout

此刻的問題是,放置在內部的RelativeLayout當進度被延伸的父的LinearLayout的高度尺寸。

這裏是我有什麼基礎。

<LinearLayout 
    android:layout_width="match_parent" 
    android:layout_height="wrap_content" 
    android:orientation="horizontal" 
    android:layout_weight="1" 
    android:weightSum="2"> 

    <RelativeLayout 
     android:id="@+id/timer1" 
     android:layout_width="0dp" 
     android:layout_height="match_parent" 
     android:layout_weight="1" 
     android:background="@android:color/darker_gray"> 

     <ProgressBar 
      android:layout_width="200dp" 
      android:layout_height="20dp" 
      style="@android:style/Widget.ProgressBar.Horizontal" 
      android:paddingLeft="16dp" 
      android:paddingRight="16dp" 
      android:layout_centerInParent="true"/> 
    </RelativeLayout> 

    <RelativeLayout 
     android:id="@+id/timer2" 
     android:layout_width="0dp" 
     android:layout_height="match_parent" 
     android:layout_weight="1" 
     android:background="@android:color/holo_blue_light"/> 

</LinearLayout> 

進度條看起來是由進度的高度上延伸父的LinearLayout的高度。當然不是想要的。

裸記住,上述的LinearLayout是內部的另一垂直的LinearLayout其中weightSum =「3」。所以這個高度的變形意味着所有的都不能垂直放入屏幕。

的一個缺陷可能我有我的想法是,因爲我還沒有完成的代碼(不把進度在三個級別),它只是一個怪癖。我會這樣做並報告回來。但在我看來,這似乎不是一件好事。

+0

更改您的第一個相對佈局的_android:layout_height =「wrap_content」_。試試看,我不確定。 –

回答

0
<LinearLayout 
    android:layout_width="match_parent" 
    android:layout_height="0dp" 
    android:orientation="horizontal" 
    android:layout_weight="1"> 

    <RelativeLayout 
     android:id="@+id/timer1" 
     android:layout_width="0dp" 
     android:layout_height="match_parent" 
     android:layout_weight="1" 
     android:background="@android:color/darker_gray"> 

     <ProgressBar 
      android:layout_width="200dp" 
      android:layout_height="20dp" 
      style="@android:style/Widget.ProgressBar.Horizontal" 
      android:paddingLeft="16dp" 
      android:paddingRight="16dp" 
      android:layout_centerInParent="true"/> 
    </RelativeLayout> 

    <RelativeLayout 
     android:id="@+id/timer2" 
     android:layout_width="0dp" 
     android:layout_height="match_parent" 
     android:layout_weight="1" 
     android:background="@android:color/holo_blue_light"/> 

</LinearLayout> 



when using weights use the width or the height to 0dp which ever orientation u need 
0

那麼你去了。之後,我充滿了三級外的LinearLayout的(在上面的示例代碼中不可見),佈局似乎自行解決。

所有高度參數是相同的(每個佔用屏幕的高度的三分之一),這是真實的在兩個模擬器上進行測試的XML預覽窗格和時。

所以在我看來,如果你有3 weightSum,則佈局將無法平衡,直到你實際上已經寫的代碼對所有三個量級。

例如,這會工作:

<LinearLayout 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    android:orientation="vertical" 
    android:wieghtSum="3" > 
    <TextView 
     android:layout_width="match_parent" 
     android:layout_height="0dp" 
     android:layout_weight="1" 
     android:text="@string/example_text" /> 
    <TextView 
     android:layout_width="match_parent" 
     android:layout_height="0dp" 
     android:layout_weight="1" 
     android:text="@string/example_text" /> 
    <TextView 
     android:layout_width="match_parent" 
     android:layout_height="0dp" 
     android:layout_weight="1" 
     android:text="@string/example_text" /> 
<LinearLayout/> 

但下面將潛在顯示的文本視圖扭曲的高度,因爲代碼是不完整的。 weightSum設置爲3,但只有兩三個師的代碼編寫。

<LinearLayout 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    android:orientation="vertical" 
    android:wieghtSum="3" > 
    <TextView 
     android:layout_width="match_parent" 
     android:layout_height="0dp" 
     android:layout_weight="1" 
     android:text="@string/example_text" /> 
    <TextView 
     android:layout_width="match_parent" 
     android:layout_height="0dp" 
     android:layout_weight="1" 
     android:text="@string/example_text" /> 
<LinearLayout/>