gpt4 book ai didi

java - 如何防止按钮和其他对象重叠?

转载 作者:太空宇宙 更新时间:2023-11-04 10:42:59 25 4
gpt4 key购买 nike

当我使用 Android 模拟器预览时,布局预览正常。但是当我在手机中安装该应用程序时, View 会重叠。这可能是因为移动屏幕空间不足,但我不知道。请帮帮我。还帮助我使这个应用程序适用于所有屏幕尺寸。提前致谢。

第一张图片是模拟器预览,第二张图片是移动预览

First image is emulator preview 2nd is mobile preview

这是 xml 代码:

<?xml version="1.0" encoding="utf-8"?>

<LinearLayout

xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingBottom="16dp"
android:paddingLeft="16dp"
android:paddingRight="16dp"
android:paddingTop="16dp"
android:orientation="vertical"
android:background="@drawable/newbackground"
tools:context=".MainActivity">

<RelativeLayout
android:layout_width="match_parent"
android:layout_height="300dp">

<ImageView
android:id="@+id/imageView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:layout_centerHorizontal="true"
android:layout_marginTop="40dp"
app:srcCompat="@drawable/dicee_logo" />
</RelativeLayout>

<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">

<ImageView
android:id="@+id/dicee_right"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
app:srcCompat="@drawable/dice1" />

<ImageView
android:id="@+id/dicee_left"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
app:srcCompat="@drawable/dice2" />

</LinearLayout>

<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">

<Button
android:id="@+id/roll_button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:layout_centerHorizontal="true"
android:layout_marginTop="61dp"
android:background="@color/colorPrimary"
android:text="@string/button_text"
android:textColor="@android:color/white" />

<Button
android:id="@+id/next_button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignEnd="@+id/roll_button"
android:layout_alignParentBottom="true"
android:layout_alignRight="@+id/roll_button"
android:layout_marginBottom="25dp"
android:background="@android:color/holo_blue_light"
android:text="Next page" />
</RelativeLayout>
</LinearLayout>

最佳答案

这将使 2 个 TextView 保持在底部,并将在您使用的任何 View 中展开

<?xml version="1.0" encoding="utf-8"?>

<LinearLayout

xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:gravity="center"
android:orientation="vertical">


<ImageView
android:id="@+id/imageView"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1"
android:scaleType="centerInside"
android:src="@drawable/ic_word" />

<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">

<ImageView
android:id="@+id/dicee_right"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
app:srcCompat="@drawable/ic_word" />

<ImageView
android:id="@+id/dicee_left"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
app:srcCompat="@drawable/ic_pdf" />

</LinearLayout>


<Button
android:id="@+id/roll_button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="30dp"
android:background="@color/colorPrimary"
android:text="text"
android:textColor="@android:color/white" />

<Button
android:id="@+id/next_button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_margin="30dp"
android:background="@android:color/holo_blue_light"
android:text="Next page" />


</LinearLayout>

关于java - 如何防止按钮和其他对象重叠?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48733617/

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