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/>