为什么这个 Android 应用程序不能在小屏幕设备上以全视图显示?

发布于 2025-01-16 20:21:21 字数 3719 浏览 2 评论 0原文

我使用相对布局并将宽度和长度设置为 match_parent。在 Redmi k30 中显示良好,但在 Pixel XL 中仅显示最多删除记录,不显示查看所有记录,并且滚动也不起作用。

我是android新手,刚刚开始布局设计,请指教。谢谢你!

它应该显示如下: 输入图片此处描述

但 Pixel XL 上缺少最后一个按钮:

在此处输入图像描述

XML 布局:

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout 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:background="#2196F3"
android:padding="10dp"
tools:context=".RUDActivity">

<TextView
    android:id="@+id/txtTitle"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:layout_marginTop="20dp"
    android:text="Please enter product ID to retrieve"
    android:textColor="#37474F"
    android:textSize="24dp" />

<EditText
    android:id="@+id/prodId"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:layout_below="@id/txtTitle"
    android:hint="Product ID"
    android:textColor="#37474F"
    android:inputType="number"
    android:textSize="24dp" />

<EditText
    android:id="@+id/name"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:layout_below="@id/prodId"
    android:layout_marginTop="30dp"
    android:hint="Name"
    android:textColor="#37474F"
    android:inputType="textPersonName"
    android:textSize="24dp" />

<EditText
    android:id="@+id/description"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:layout_below="@id/name"
    android:hint="Description"
    android:textColor="#37474F"
    android:inputType="text"
    android:textSize="24dp" />

<EditText
    android:id="@+id/price"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:layout_below="@id/description"
    android:hint="Price"
    android:textColor="#37474F"
    android:inputType="numberDecimal"
    android:textSize="24dp" />

<EditText
    android:id="@+id/quantity"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:layout_below="@id/price"
    android:hint="Quantity"
    android:textColor="#37474F"
    android:inputType="number"
    android:textSize="24dp" />

<Button
    android:id="@+id/btnSearch"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:layout_below="@id/quantity"
    android:layout_marginTop="30dp"
    android:text="Search Data"
    android:textSize="24dp" />

<Button
    android:id="@+id/btnView"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:layout_below="@id/btnDelete"
    android:layout_marginTop="30dp"
    android:text="View All Record"
    android:textSize="24dp" />

<Button
    android:id="@+id/btnUpdate"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:layout_below="@id/btnSearch"
    android:layout_marginTop="30dp"
    android:text="Update Record"
    android:textSize="24dp" />

<Button
    android:id="@+id/btnDelete"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:layout_below="@id/btnUpdate"
    android:layout_marginTop="30dp"
    android:text="Delete Record"
    android:textSize="24dp" />

I'm using Relative Layout and I set the width and length to match_parent. It displays fine in Redmi k30 but in Pixel XL it only display up-to Delete Record, it does not display View All Record and scrolling also does not work.

I'm new to android and just starting layout designs, please advice. Thank you!

It should display like this:
enter image description here

But on Pixel XL the last button is missing:

enter image description here

XML layout:

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout 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:background="#2196F3"
android:padding="10dp"
tools:context=".RUDActivity">

<TextView
    android:id="@+id/txtTitle"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:layout_marginTop="20dp"
    android:text="Please enter product ID to retrieve"
    android:textColor="#37474F"
    android:textSize="24dp" />

<EditText
    android:id="@+id/prodId"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:layout_below="@id/txtTitle"
    android:hint="Product ID"
    android:textColor="#37474F"
    android:inputType="number"
    android:textSize="24dp" />

<EditText
    android:id="@+id/name"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:layout_below="@id/prodId"
    android:layout_marginTop="30dp"
    android:hint="Name"
    android:textColor="#37474F"
    android:inputType="textPersonName"
    android:textSize="24dp" />

<EditText
    android:id="@+id/description"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:layout_below="@id/name"
    android:hint="Description"
    android:textColor="#37474F"
    android:inputType="text"
    android:textSize="24dp" />

<EditText
    android:id="@+id/price"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:layout_below="@id/description"
    android:hint="Price"
    android:textColor="#37474F"
    android:inputType="numberDecimal"
    android:textSize="24dp" />

<EditText
    android:id="@+id/quantity"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:layout_below="@id/price"
    android:hint="Quantity"
    android:textColor="#37474F"
    android:inputType="number"
    android:textSize="24dp" />

<Button
    android:id="@+id/btnSearch"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:layout_below="@id/quantity"
    android:layout_marginTop="30dp"
    android:text="Search Data"
    android:textSize="24dp" />

<Button
    android:id="@+id/btnView"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:layout_below="@id/btnDelete"
    android:layout_marginTop="30dp"
    android:text="View All Record"
    android:textSize="24dp" />

<Button
    android:id="@+id/btnUpdate"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:layout_below="@id/btnSearch"
    android:layout_marginTop="30dp"
    android:text="Update Record"
    android:textSize="24dp" />

<Button
    android:id="@+id/btnDelete"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:layout_below="@id/btnUpdate"
    android:layout_marginTop="30dp"
    android:text="Delete Record"
    android:textSize="24dp" />

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

坠似风落 2025-01-23 20:21:21

欢迎来到 android..

想象一下在一个黑暗的房间里将 15 个人排成 5 排,每排 3 人。
如果无论房间的尺寸如何,都必须使它们看起来相同,那么空间就不可能相同。

Redmi 和 Pixel XL 是高密度、长设备。

您可以使用此库Intuit SDK 库作为维度。该库有助于根据屏幕尺寸自动缩放。

然而,您必须将 ConstraintLayout 与 matchConstraints 结合使用,并提出一个设计理念,使其在大多数设备中看起来都相同。

例如:将上部表格 1 部分和下部按钮制成另一个部分。
并且不要遵循自上而下的方法,使表单部分粘在顶部,按钮部分粘在底部。

  1. 对于滚动,您必须使用 ScrollView 并将布局包装在其中,这是一个很好的 Stackover Flow 问题开始

Welcome to android..

Think of arranging 15 people in 5 rows of 3 in a dark room.
If you have to make them look the same whatever the dimensions of the room might be then the space cannot be the same.

Redmi and Pixel XL are high density and long devices.

You can use this library Intuit SDK library for the dimensions. This library helps to automatically scale depending on the screen size.

Going forward However you have to use ConstraintLayout with matchConstraints and come up with a design idea that makes it look the same in most devices.

For eg: Making the upper form 1 section and the lower buttons another.
And instead of following a top-down approach make the form part stick to the top and the buttons part to the bottom.

  1. For the scroll you have to use a ScrollView and wrap your layouts within it , Here is a good Stackover FLow Question to get started
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文