LinearLayout 未正确调整 ImageView 的大小

LinearLayout not resizing ImageViews correctly

作为我的应用 on-boarding 的一部分,我有一系列突出显示 UI 的半透明叠加层。每一个都是一个 LinearLayout,最初是不可见的(实际上是 "gone"),我依次将其设置为可见。我很难让其中之一在平板电脑和 phones 上正确显示,无论是纵向还是横向。我可以将其调整为在 phone 上工作,但在 tablet-portrait 上显示效果不佳。

此处的图像设置为在 10" 平板电脑上纵向显示良好,它们在 7" 平板电脑和 phones 上纵向显示,但在横向显示时无效。在下图中,我希望箭头(两个 ImageView)根据需要调整大小以为文本腾出空间。但是,无论我做什么,Layout 似乎都优先考虑 ImageViews。

(请注意,我确实意识到我可以在某种程度上使用 RelativeLayout 来完成这项工作,但是,据我所知,我无法使用 RelativeLayout 使半透明背景工作,填充屏幕。 )

我的问题简述:有没有办法让 LinearLayout 优先考虑 TextViews,给它们足够的 space,并调整 ImageViews 的大小以适应其余部分?

这是一个很好的布局(10 英寸平板电脑,纵向,按缩小比例显示):

这里有一些文本被截断的错误(10 英寸平板电脑,横向,缩小比例):

这是另一个不好的 (phone):

我没有其他调整的屏幕截图,但它显示了大箭头并且没有中央 "Tap to Continue" 按钮。

这是我现在的 XML:

<RelativeLayout
    android:id="@+id/main_holder"
    xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent">

    <LinearLayout
        android:id="@+id/intro3"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:gravity="center"
        android:orientation="vertical"
        android:visibility="gone"
        android:onClick="introClicked"
        android:clickable="true">

        <LinearLayout
            android:id="@+id/intro3_top"
            android:layout_width="match_parent"
            android:layout_height="0dp"
            android:layout_weight="1"
            android:layout_gravity="top|center_horizontal"
            android:orientation="vertical"
            android:gravity="top|center_horizontal">
            <TextView
                android:id="@+id/textViewIntro3_1"
                fontPath="fonts/AsCuteAs...Heavy.ttf"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:text="Swipe up to mark a spark completed."
                android:layout_gravity="center_horizontal|top"
                android:gravity="center"
                android:layout_weight="1"
                android:paddingBottom="5dp"
                android:background="#C5000000"
                android:textColor="#fff6c3"
                android:textSize="30sp"/>
            <ImageView
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:layout_gravity="center_horizontal|bottom"
                android:adjustViewBounds="false"
                android:background="@drawable/grad_bottom"
                android:padding="10dp"
                android:layout_weight="1"
                android:scaleType="fitCenter"
                android:src="@drawable/arrow_up"/>
        </LinearLayout>

        <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="100dp"
            android:orientation="vertical"
            android:layout_weight="0"
            android:background="#85000000"
            android:gravity="center">

            <TextView
                android:id="@+id/button_intro3"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_gravity="center"
                android:alpha="0"
                android:background="@drawable/roundrect"
                android:onClick="introClicked"
                android:padding="10dp"
                android:text="Tap to Continue"
                android:clickable="true"
                android:enabled="true"
                android:textColor="#FFFFF6C3"
                android:textSize="24sp"/>
        </LinearLayout>

        <LinearLayout
            android:id="@+id/intro3_bottom"
            android:layout_width="match_parent"
            android:layout_height="0dp"
            android:orientation="vertical"
            android:layout_weight="1"
            android:layout_gravity="bottom|center_horizontal"
            android:gravity="bottom|center_horizontal">
            <ImageView
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:layout_gravity="center_horizontal|bottom"
                android:adjustViewBounds="false"
                android:background="@drawable/grad_top"
                android:layout_weight="1"
                android:padding="10dp"
                android:scaleType="fitCenter"
                android:src="@drawable/arrow_down"/>
            <TextView
                android:id="@+id/textViewIntro3_2"
                fontPath="fonts/AsCuteAs...Heavy.ttf"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:text="Swipe down to reject.\n "
                android:layout_gravity="center_horizontal|bottom"
                android:gravity="center"
                android:layout_weight="1"
                android:paddingBottom="0dp"
                android:background="#C5000000"
                android:textColor="#fff6c3"
                android:textSize="30sp"/>
        </LinearLayout>
    </LinearLayout>
</RelativeLayout>

有几种可能的方法。我已经稍微更新了您的布局,所以现在它应该符合您的期望:

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout
    android:id="@+id/main_holder"
    xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent">

    <RelativeLayout
        android:id="@+id/intro3"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:visibility="gone"
        android:onClick="introClicked"
        android:clickable="true">

        <TextView
            android:id="@+id/textViewIntro3_1"
            fontPath="fonts/AsCuteAs...Heavy.ttf"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:text="Swipe up to mark a spark completed."
            android:gravity="center"
            android:layout_alignParentTop="true"
            android:paddingBottom="5dp"
            android:background="#C5000000"
            android:textColor="#fff6c3"
            android:textSize="30sp"/>
        <ImageView
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_above="@+id/button_intro3"
            android:layout_below="@+id/textViewIntro3_1"
            android:adjustViewBounds="false"
            android:background="@drawable/grad_bottom"
            android:padding="10dp"
            android:scaleType="fitCenter"
            android:src="@drawable/arrow_up"/>

        <TextView
            android:id="@+id/button_intro3"
            android:layout_centerInParent="true"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_gravity="center"
            android:alpha="0"
            android:background="@drawable/roundrect"
            android:onClick="introClicked"
            android:padding="10dp"
            android:text="Tap to Continue"
            android:clickable="true"
            android:enabled="true"
            android:textColor="#FFFFF6C3"
            android:textSize="24sp"/>

        <ImageView
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:adjustViewBounds="false"
            android:background="@drawable/grad_top"
            android:layout_below="@+id/button_intro3"
            android:layout_above="@+id/textViewIntro3_2"
            android:padding="10dp"
            android:scaleType="fitCenter"
            android:src="@drawable/arrow_down"/>
        <TextView
            android:id="@+id/textViewIntro3_2"
            fontPath="fonts/AsCuteAs...Heavy.ttf"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:text="Swipe down to reject.\n "
            android:gravity="center"
            android:layout_alignParentBottom="true"
            android:paddingBottom="0dp"
            android:background="#C5000000"
            android:textColor="#fff6c3"
            android:textSize="30sp"/>
    </RelativeLayout>
</RelativeLayout>

我在这里所做的是用 RelativeLayout 而不是 LinearLayout 重写布局。以我的拙见,它更适合这里。

希望对你有帮助。