简体   繁体   English

android ProgressBar更改父级LinearLayout的高度尺寸

[英]android ProgressBar is changing height dimension of parent LinearLayout

I have a bunch of RelativeLayout inside LinearLayout. 我在LinearLayout中有一堆RelativeLayout。 Inside this will be ProgressBar and other elements. 在此内部将是ProgressBar和其他元素。

The problem at the moment is that the ProgressBar is extending the height dimension of the parent LinearLayout when placed inside the RelativeLayout. 目前的问题是,当放置在RelativeLayout中时,ProgressBar正在扩展父级LinearLayout的高度尺寸。

Here's the basics of what I have. 这是我所拥有的基本知识。

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

The ProgressBar looks like it is extending height of the parent LinearLayout by the height of the ProgressBar. ProgressBar看起来像是将父LinearLayout的高度扩展了ProgressBar的高度。 Which of course is not wanted. 当然哪个都不想要。

Bare in mind that the above LinearLayout is inside another vertical LinearLayout where weightSum="3". 切记上面的LinearLayout在另一个垂直LinearLayout内,其中weightSum =“ 3”。 So this distortion of the height means all will not fit in the screen vertically. 因此,高度的这种变形意味着所有人都无法垂直放入屏幕中。

The one flaw I may have in my thinking is that because I have not yet completed the code (not put ProgressBar in each of the three levels) that it's just a quirk. 我认为可能存在的一个缺陷是,由于我尚未完成代码(未将ProgressBar放在三个级别中的每个级别中),因此这只是一个怪癖。 I'll do that and report back. 我会做并报告。 But it still seems to me this can't be a good thing. 但是在我看来,这仍然不是一件好事。

<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

Well there you go. 好吧,你去。 After I filled all three levels of the outer LinearLayout (not visible in example code above), the layout seemed to sort itself out. 在我填充了外部LinearLayout的所有三个级别(在上面的示例代码中不可见)之后,布局似乎已经整理好了。

All height parameters are the same (each taking up one third of the height of the screen) and this is true in both the xml Preview pane and when tested on an emulator. 所有的高度参数都相同(每个参数都占据屏幕高度的三分之一),在xml预览窗格中以及在模拟器上进行测试时都是如此。

So it looks to me that if you have a weightSum of 3, then the layout will not balance out until you have actually written the code for all three weight divisions. 因此,在我看来,如果您的weightSum为3,那么在您实际上为所有三个权重划分编写代码之前,布局不会平衡。

For example, this would work: 例如,这将起作用:

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

But the following would potentially show a distorted height of the text views because the code is incomplete. 但是以下内容可能显示文本视图的高度失真,因为代码不完整。 weightSum is set to 3 but only code for two of the three divisions is written. 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/>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM