Android 如何在背景图像较大的情况下减小线性布局的尺寸

Android 如何在背景图像较大的情况下减小线性布局的尺寸,android,android-layout,android-linearlayout,android-layout-weight,Android,Android Layout,Android Linearlayout,Android Layout Weight,我试图垂直绘制两个布局,顶部一个包含图像,因为图像非常大,它占据了botton一半的一部分,我使用权重=1和Layouthweight=0dp对其进行等分 没有任何图像,分区是完美的,但是如果我将背景图像设置为toplayout,权重比就不完美,这是不可重用的 我试过使用framelayout,但也没用 在xml中,不通过编程来分配布局高度的确切方法是什么。尝试以下方法: <LinearLayout xmlns:android="http://schemas.android.com/apk

我试图垂直绘制两个布局,顶部一个包含图像,因为图像非常大,它占据了botton一半的一部分,我使用权重=1和Layouthweight=0dp对其进行等分

没有任何图像,分区是完美的,但是如果我将背景图像设置为toplayout,权重比就不完美,这是不可重用的

我试过使用framelayout,但也没用

在xml中,不通过编程来分配布局高度的确切方法是什么。

尝试以下方法:

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:orientation="vertical" android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:weightSum="1">

    <LinearLayout
        android:orientation="vertical"
        android:layout_width="match_parent"
        android:layout_height="0dp"
        android:layout_weight="0.5">
   </LinearLayout>

    <LinearLayout
        android:orientation="vertical"
        android:layout_width="match_parent"
        android:layout_height="0dp"
        android:layout_weight="0.5">
    </LinearLayout>
</LinearLayout>


然后,您可以将图像设置为顶部布局的背景。

如果您想为视图提供相对空间,您可以尝试使用新的android库

支持率库

您可以在项目中使用它,如:

<android.support.percent.PercentFrameLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent">

        <ImageView
            android:layout_width="0dp"
            android:layout_height="0dp"
            app:layout_heightPercent="50%"
            app:layout_widthPercent="100%" />

        <TextView
            android:layout_width="0dp"
            android:layout_height="0dp"
            android:layout_gravity="bottom"
            app:layout_heightPercent="50%"
            app:layout_widthPercent="100%" />

    </android.support.percent.PercentFrameLayout>


添加到您的主版面
android:weightSum=“1”
@ArturSzymański感谢您的评论。这不起作用,当您设置版面的图像集较大时,权重不会受到影响。@Rakesh您在哪个版面上应用背景图像?大家好,终于明白问题的根源,这不是因为图像,但是由于我在linearlayout的后半部分添加了coverflow,但是它在运行时工作得非常好。