gpt4 book ai didi

android - LinearLayout 未正确调整 ImageView 的大小

转载 作者:行者123 更新时间:2023-11-30 01:42:08 27 4
gpt4 key购买 nike

作为我的应用入门指南的一部分,我有一系列突出显示 UI 的半透明叠加层。每一个都是一个 LinearLayout,最初是不可见的(实际上“消失了”),我依次使其可见。我很难让其中之一在平板电脑和手机上正确显示,无论是纵向还是横向。我可以调整它以在手机上工作,但它在平板电脑上的纵向显示效果不佳。

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

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

我的问题简要说明:有没有办法让 LinearLayout 优先考虑 TextView,给它们足够的空间,并调整 ImageView 的大小以适应其余部分?

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

这是一个糟糕的例子,其中一些文字被截断了(10 英寸平板电脑,横向,缩小比例): 10" tablet, landscape

这是另一个不好的(电话): phone, portrait

我没有其他调整的屏幕截图,但它显示了大箭头并且没有中央“点击以继续”按钮。

这是我当前的 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 重写布局。以我的拙见,它更适合这里。

希望对您有所帮助。

关于android - LinearLayout 未正确调整 ImageView 的大小,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34354034/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com