gpt4 book ai didi

android - 错误的 xml 或 android 兼容性问题?

转载 作者:行者123 更新时间:2023-11-29 01:50:39 25 4
gpt4 key购买 nike

我正在 android 上开发我的第一个应用程序,我认为我的应用程序满足支持多个屏幕所需的要求(仅使用 dp 或 sp 等...)。

但是,我似乎做错了什么。 Textviews 在屏幕底部重叠。

现在...我是否编写了错误的 xml 或我是否需要为每个 android 版本添加不同的布局,以确保避免此类问题?

第一个设备规范 (docomo ARROWS NX F-06E) 1080×1920 像素,16,777,216 色第一张设备截图:

http://s15.postimg.org/r8tp0oay3/Screenshot_2013_08_19_22_08_33.png

第二个设备规范 (LG L-07C Optimus) 480 x 800 像素,256K 色第二台设备截图: http://s22.postimg.org/xkqbne74h/i001.jpg

这是xml代码。

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/myLayout"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="@color/dark_green"
android:orientation="vertical"
>

<ImageView
android:id="@+id/image"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_marginTop="5dp"
android:src="@drawable/sakai" />

<TextView
android:id="@+id/random_field"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="false"
android:layout_alignParentRight="false"
android:layout_alignTop="@id/image"
android:layout_toLeftOf="@+id/chronometer"
android:layout_toRightOf="@id/image"
android:background="@drawable/bubble_bl"
android:text="@string/index"
android:textSize="20.5sp" />

<Chronometer android:id="@+id/chronometer"
android:format="@string/chronometer_initial_format"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_marginRight="0dip"
android:layout_weight="0.5"
android:paddingBottom="30dip"
android:paddingTop="30dip"
/>
<Button
android:layout_below="@id/image"
android:id="@+id/askquestion"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="@string/ask"
style="@style/ButtonText"
android:background="@drawable/btn_blue_states"
/>
<Button
android:layout_below="@id/askquestion"
android:id="@+id/answer1"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="@string/ask"
style="@style/ButtonText"
android:background="@drawable/btn_blue_states"/>
<Button
android:layout_below="@id/answer1"
android:id="@+id/answer2"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="@string/ask"
style="@style/ButtonText"
android:background="@drawable/btn_blue_states"/>
<Button
android:id="@+id/answer3"
android:layout_below="@id/answer2"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="@string/ask"
style="@style/ButtonText"
android:background="@drawable/btn_blue_states" />
<Button
android:id="@+id/answer4"
android:layout_below="@id/answer3"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="@string/ask"
style="@style/ButtonText"
android:background="@drawable/btn_blue_states"/>
<TextView
android:id="@+id/score_field"
android:layout_below="@id/answer4"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_marginBottom="5dip"
android:gravity="center"
android:text="@string/score"
android:textSize="24.5sp"
/>
<TextView
android:id="@+id/performance_field"
android:layout_below="@id/score_field"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:gravity="center"
android:textSize="24.5sp"
/>

<LinearLayout android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="vertical" android:layout_alignParentBottom="true"
android:weightSum="4.0" >
<TextView
android:id="@+id/difficult_textview"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:gravity="center"
android:text="@string/difficulty"
android:textSize="24.5sp"
/>
<LinearLayout android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:id="@+id/linearLayoutWithButtons"
android:orientation="horizontal"
android:weightSum="4.0" >

<Button
android:id="@+id/diff1"
style="@style/ButtonText"
android:layout_weight="1.0"
android:layout_height="wrap_content"
android:background="@drawable/btn_blue_states"
android:text="@string/one" />
<Button
android:id="@+id/diff2"
style="@style/ButtonText"
android:layout_weight="1.0"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="@drawable/btn_blue_states"
android:text="@string/two" />
<Button
android:id="@+id/diff3"
style="@style/ButtonText"
android:layout_weight="1.0"
android:layout_height="wrap_content"
android:background="@drawable/btn_blue_states"
android:text="@string/three" />
<Button
android:id="@+id/diff4"
style="@style/ButtonText"
android:layout_weight="1.0"
android:layout_height="wrap_content"
android:background="@drawable/btn_blue_states"
android:text="@string/four" />

</LinearLayout>

</LinearLayout>

最佳答案

这是一个简单的纵横比问题:

  • 1080x1920 为 16:9
  • 480x800 是 5:3

所以更高分辨率的屏幕是一个更长(更高)的矩形。您的布局设计得很好,部分布局将卡在底部,另一部分会卡在顶部,但您在设计它时考虑到了较高的屏幕,因此所有内容都在较小的屏幕上运行。您有以下两种选择之一:

  1. 重新设计布局以适合较短的屏幕,在这种情况下,在较高的屏幕上它只会拉伸(stretch)以显示顶部和底部部分之间的更多额外空间。
  2. 使用资源限定符根据高度为屏幕创建两种不同的布局。仅当您尝试实现像素更完美的外观而不管设备的屏幕尺寸如何时,这种程度的努力才有意义。

关于android - 错误的 xml 或 android 兼容性问题?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18315581/

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