gpt4 book ai didi

java - 移动设备中的不同 XML

转载 作者:行者123 更新时间:2023-12-01 09:41:36 25 4
gpt4 key购买 nike

我有这个 XML 代码:

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

<EditText
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:id="@+id/editText"
android:hint="enter your name"
android:layout_alignParentTop="true"
android:layout_centerHorizontal="true" />

<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="button"
android:id="@+id/button"
android:layout_below="@+id/editText"
android:layout_centerHorizontal="true"
android:layout_marginTop="20dp"/>

<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceLarge"
android:text="name"
android:id="@+id/textView8"
android:layout_below="@+id/button"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:layout_marginLeft="20dp"/>

<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/button2"
android:text="copy"
android:layout_alignBottom="@+id/textView8"
android:layout_alignParentRight="true"
android:layout_alignParentEnd="true" />
</RelativeLayout>

在 AVD 中,它看起来像这样:

enter image description here

在移动设备中,它看起来像这样:

enter image description here

怎样才能让它们看起来一样?

最佳答案

出现这种差异是因为您非常不小心地使用了RelativeLayout。相对布局将项目相对于彼此定位,因此在不同设备上看起来可能会有所不同。

我建议您使用一个垂直 LinearLayout 并让它有 2 个水平 LinearLayouts 作为其子级,作为放置这些字段的行。我将在下面提供您的一些修改后的代码,但请记住,这在每个设备上看起来都是相同的, 并且您需要使其看起来更漂亮,因为这只是一个示例。像这样的事情:

<LinearLayout 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"
android:orientation="vertical">

<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="wawdsd"/>
</LinearLayout>

<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:baselineAligned="true">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceLarge"
android:text="name"
android:id="@+id/textView8" />
<EditText
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:id="@+id/editText"
android:hint="enter your name" />

<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="button"
android:id="@+id/button"
android:layout_marginTop="20dp"/>

<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/button2"
android:text="copy"/>
</LinearLayout>

关于java - 移动设备中的不同 XML,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38411990/

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