Android 安卓框架布局内2个不同高度的重叠视图,使其高度相同

Android 安卓框架布局内2个不同高度的重叠视图,使其高度相同,android,layout,view,height,Android,Layout,View,Height,我有一个进度条和一个框架布局内的文本视图。文本与进度条重叠 文本视图的高度是进度条高度的两倍(由于文本的长度),我希望进度条的高度能够自动调整 我尝试通过将进度条设置为与父项匹配,并让父项包装内容,但进度条的高度不会增加 XML是这样的: <FrameLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:lay

我有一个进度条和一个框架布局内的文本视图。文本与进度条重叠

文本视图的高度是进度条高度的两倍(由于文本的长度),我希望进度条的高度能够自动调整

我尝试通过将进度条设置为与父项匹配,并让父项包装内容,但进度条的高度不会增加

XML是这样的:

<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
> 

<ProgressBar  
    android:layout_width="match_parent"  
    style="?android:attr/progressBarStyleHorizontal"  
    android:layout_height="fill_parent"
    android:layout_gravity="center_horizontal|center_vertical"
/> 

<TextView
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:textSize="30sp"
    android:text="Big long text here................................"    
    android:layout_gravity="center_horizontal|center_vertical"
/>

</FrameLayout>

对ProgressBar和TextView使用android:layout_weight=“1”的LinearLayout。像这样的

<LinearLayout android:layout_height="match_parent"
 android:layout_width="match_parent"
 android:orientation="vertical> 
 <ProgressBar  
android:layout_width="match_parent"  
style="?android:attr/progressBarStyleHorizontal"  
android:layout_height="0dp"
android:layout_gravity="center_horizontal|center_vertical"
android:layout_weight="1"
/> 

<TextView
android:layout_width="wrap_content"
android:layout_height="0dp"
android:textSize="30sp"
android:text="Big long text here................................"    
android:layout_gravity="center_horizontal|center_vertical"
android:layout_weight="1"
/>
</LinearLayout>

对ProgressBar和TextView使用android:layout_weight=“1”的LinearLayout。像这样的

<LinearLayout android:layout_height="match_parent"
 android:layout_width="match_parent"
 android:orientation="vertical> 
 <ProgressBar  
android:layout_width="match_parent"  
style="?android:attr/progressBarStyleHorizontal"  
android:layout_height="0dp"
android:layout_gravity="center_horizontal|center_vertical"
android:layout_weight="1"
/> 

<TextView
android:layout_width="wrap_content"
android:layout_height="0dp"
android:textSize="30sp"
android:text="Big long text here................................"    
android:layout_gravity="center_horizontal|center_vertical"
android:layout_weight="1"
/>
</LinearLayout>

使用相对定位,并使用布局对齐对齐边界

 <RelativeLayout
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        android:focusable="false">
        <TextView
            android:id="@+id/textview"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:textSize="30sp"
            android:text="Big long text here................................"
            android:layout_gravity="center_horizontal|center_vertical" />
        <ProgressBar
            style="?android:attr/progressBarStyleHorizontal"
            android:layout_height="fill_parent"
            android:layout_gravity="center_horizontal|center_vertical"
            android:layout_alignTop="@id/textview"
            android:layout_alignLeft="@id/textview"
            android:layout_alignBottom="@id/textview" />
    </RelativeLayout>

使用相对线并使用布局对齐对齐边界

 <RelativeLayout
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        android:focusable="false">
        <TextView
            android:id="@+id/textview"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:textSize="30sp"
            android:text="Big long text here................................"
            android:layout_gravity="center_horizontal|center_vertical" />
        <ProgressBar
            style="?android:attr/progressBarStyleHorizontal"
            android:layout_height="fill_parent"
            android:layout_gravity="center_horizontal|center_vertical"
            android:layout_alignTop="@id/textview"
            android:layout_alignLeft="@id/textview"
            android:layout_alignBottom="@id/textview" />
    </RelativeLayout>


我爱你。非常感谢。textview必须在xml中的progressbar之后(显示在其上方)。这需要将progressbar标记中的android:layout_alignTop=“@id/textview”等替换为android:layout_alignTop=“@+id/textview”(因为尚未定义id)。它工作得很好!我爱你。非常感谢。textview必须在xml中的progressbar之后(显示在其上方)。这需要将progressbar标记中的android:layout_alignTop=“@id/textview”等替换为android:layout_alignTop=“@+id/textview”(因为尚未定义id)。它工作得很好!匹配父项和填充父项?匹配父项和填充父项?