AndroidrelativeLayout中不同的GUI分辨率
我有一个关于 Android 中不同分辨率的问题。我已经在RelativeLayout 中编写了一个xml GUI 文件。我创建了小图片,除了图片之外我还想要文本视图。当我更改分辨率时,我的问题出现了,文本视图“文本”移动,我担心这在不同的分辨率下看起来会很糟糕。
我现在所做的,例如创建一个图像,在该图像的右侧创建一个文本视图,该文本视图位于另一个具有例如 19 像素的图像下方。 但如果我更改分辨率,19 个像素的距离可能太大或太小,并且来自 texview 的文本将显示在屏幕上的错误位置。
我如何使用不同的分辨率来克服这个问题,并使用 RealtiveLayout 创建一个定义像素距离的 GUI。通常我希望不同文本视图之间的距离约为 20 像素,如下面的代码所示。
这是我的示例代码:
<?xml version="1.0" encoding="utf-8"?>
<ScrollView android:id="@+id/ScrollView01"
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_height="wrap_content"
android:layout_width="fill_parent"
>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:stretchColumns="1"
android:weightSum="1.0"
android:background="#adaeb5">
<TextView android:text="@+id/TextView03" android:id="@+id/TextView03"
android:layout_width="wrap_content" android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:textStyle="bold"
android:textSize="21dp"
android:shadowDy="1.5"
android:textColor="#FFFFFF"
android:shadowColor="#212421"
android:shadowRadius="1.5"
android:shadowDx="1.5"/>
<ImageView android:id="@+id/ImageView01"
android:layout_width="wrap_content" android:layout_height="wrap_content"
android:layout_below="@+id/TextView03" android:paddingTop="35px"
/>
<ImageView android:id="@+id/ImageView02"
android:layout_width="wrap_content" android:layout_height="wrap_content"
android:layout_below="@+id/ImageView01" android:paddingTop="20px"
/>
<ImageView android:id="@+id/ImageView03"
android:layout_width="wrap_content" android:layout_height="wrap_content"
android:layout_below="@+id/ImageView02" android:paddingTop="20px"
/>
<ImageView android:id="@+id/ImageView04"
android:layout_width="wrap_content" android:layout_height="wrap_content"
android:layout_below="@+id/ImageView03" android:paddingTop="20px"
/>
<TextView android:text="@+id/TextView01" android:id="@+id/TextView01"
android:shadowDy="1.0"
android:shadowColor="#bdbebd"
android:shadowRadius="1.0"
android:shadowDx="1.0"
android:layout_width="wrap_content" android:layout_height="wrap_content" android:textColor="#212421"
android:layout_toRightOf="@+id/ImageView01" android:layout_below="@+id/TextView03" android:paddingTop="36px"/>
<TextView android:text="@+id/TextView02" android:id="@+id/TextView02"
android:shadowDy="1.0"
android:shadowColor="#bdbebd"
android:shadowRadius="1.0"
android:shadowDx="1.0"
android:layout_width="wrap_content" android:layout_height="wrap_content" android:textColor="#212421"
android:layout_below="@+id/TextView01" android:layout_toRightOf="@+id/ImageView02" android:paddingTop="25px"/>
<TextView android:text="@+id/TextView04" android:id="@+id/TextView04"
android:shadowDy="1.0"
android:shadowColor="#bdbebd"
android:shadowRadius="1.0"
android:shadowDx="1.0"
android:layout_width="wrap_content" android:layout_height="wrap_content" android:textColor="#212421"
android:layout_below="@+id/TextView02" android:layout_toRightOf="@+id/ImageView03" android:paddingTop="15px"/>
<TextView android:text="@+id/TextView05" android:id="@+id/TextView05"
android:shadowDy="1.0"
android:shadowColor="#bdbebd"
android:shadowRadius="1.0"
android:shadowDx="1.0"
android:layout_width="wrap_content" android:layout_height="wrap_content" android:textColor="#212421"
android:layout_below="@+id/TextView04" android:layout_toRightOf="@+id/ImageView04" android:paddingTop="19px"/>
<TextView android:text="@+id/TextView07" android:id="@+id/TextView07"
android:textStyle="bold"
android:textSize="21dp"
android:shadowDy="1.5"
android:textColor="#FFFFFF"
android:shadowColor="#212421"
android:shadowRadius="1.5"
android:shadowDx="1.5"
android:layout_width="wrap_content" android:layout_height="wrap_content"
android:layout_centerHorizontal="true" android:layout_below="@+id/TextView05" android:paddingTop="30px"/>
<TextView android:text="@+id/TextView08" android:id="@+id/TextView08"
android:shadowDy="1.0"
android:shadowColor="#bdbebd"
android:shadowRadius="1.0"
android:shadowDx="1.0"
android:paddingLeft="20px"
android:paddingRight="25px"
android:layout_width="wrap_content" android:layout_height="wrap_content" android:textColor="#212421" android:textSize="16dp"
android:layout_below="@+id/TextView07" android:layout_toRightOf="@+id/ImageView05" android:paddingTop="20px" android:paddingBottom="20px"/>
<Button android:id="@+id/help_button2" android:layout_below="@+id/TextView08"
android:layout_width="wrap_content" android:layout_height="wrap_content"
android:layout_centerHorizontal="true" android:text="Previous" />
</RelativeLayout>
</ScrollView>
/thx 提前
I have a question about different resolutions in android. I have coded a xml GUI file in RelativeLayout. Ive created small pictures, and beside the pictures I want textviews. My problem occurs when I change the resolution, the textviews "texts" moves, and I am affraid this will look bad in different resolutions.
What I have done now, I for example create a image, toRightOf that image I create a textview and this textview is below another image with for example 19 pixels.
But if I change the resolution, the 19 pixels can be to much or to low in distance, and the text from the texview will be shown in the wrong position on the screen.
How can i overcome this problem with different resolutions and creating a GUI with RealtiveLayout that defines distances in pixels. Often I want a distance around 20 pixels between different textviews as you see in my code below.
This is my example code:
<?xml version="1.0" encoding="utf-8"?>
<ScrollView android:id="@+id/ScrollView01"
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_height="wrap_content"
android:layout_width="fill_parent"
>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:stretchColumns="1"
android:weightSum="1.0"
android:background="#adaeb5">
<TextView android:text="@+id/TextView03" android:id="@+id/TextView03"
android:layout_width="wrap_content" android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:textStyle="bold"
android:textSize="21dp"
android:shadowDy="1.5"
android:textColor="#FFFFFF"
android:shadowColor="#212421"
android:shadowRadius="1.5"
android:shadowDx="1.5"/>
<ImageView android:id="@+id/ImageView01"
android:layout_width="wrap_content" android:layout_height="wrap_content"
android:layout_below="@+id/TextView03" android:paddingTop="35px"
/>
<ImageView android:id="@+id/ImageView02"
android:layout_width="wrap_content" android:layout_height="wrap_content"
android:layout_below="@+id/ImageView01" android:paddingTop="20px"
/>
<ImageView android:id="@+id/ImageView03"
android:layout_width="wrap_content" android:layout_height="wrap_content"
android:layout_below="@+id/ImageView02" android:paddingTop="20px"
/>
<ImageView android:id="@+id/ImageView04"
android:layout_width="wrap_content" android:layout_height="wrap_content"
android:layout_below="@+id/ImageView03" android:paddingTop="20px"
/>
<TextView android:text="@+id/TextView01" android:id="@+id/TextView01"
android:shadowDy="1.0"
android:shadowColor="#bdbebd"
android:shadowRadius="1.0"
android:shadowDx="1.0"
android:layout_width="wrap_content" android:layout_height="wrap_content" android:textColor="#212421"
android:layout_toRightOf="@+id/ImageView01" android:layout_below="@+id/TextView03" android:paddingTop="36px"/>
<TextView android:text="@+id/TextView02" android:id="@+id/TextView02"
android:shadowDy="1.0"
android:shadowColor="#bdbebd"
android:shadowRadius="1.0"
android:shadowDx="1.0"
android:layout_width="wrap_content" android:layout_height="wrap_content" android:textColor="#212421"
android:layout_below="@+id/TextView01" android:layout_toRightOf="@+id/ImageView02" android:paddingTop="25px"/>
<TextView android:text="@+id/TextView04" android:id="@+id/TextView04"
android:shadowDy="1.0"
android:shadowColor="#bdbebd"
android:shadowRadius="1.0"
android:shadowDx="1.0"
android:layout_width="wrap_content" android:layout_height="wrap_content" android:textColor="#212421"
android:layout_below="@+id/TextView02" android:layout_toRightOf="@+id/ImageView03" android:paddingTop="15px"/>
<TextView android:text="@+id/TextView05" android:id="@+id/TextView05"
android:shadowDy="1.0"
android:shadowColor="#bdbebd"
android:shadowRadius="1.0"
android:shadowDx="1.0"
android:layout_width="wrap_content" android:layout_height="wrap_content" android:textColor="#212421"
android:layout_below="@+id/TextView04" android:layout_toRightOf="@+id/ImageView04" android:paddingTop="19px"/>
<TextView android:text="@+id/TextView07" android:id="@+id/TextView07"
android:textStyle="bold"
android:textSize="21dp"
android:shadowDy="1.5"
android:textColor="#FFFFFF"
android:shadowColor="#212421"
android:shadowRadius="1.5"
android:shadowDx="1.5"
android:layout_width="wrap_content" android:layout_height="wrap_content"
android:layout_centerHorizontal="true" android:layout_below="@+id/TextView05" android:paddingTop="30px"/>
<TextView android:text="@+id/TextView08" android:id="@+id/TextView08"
android:shadowDy="1.0"
android:shadowColor="#bdbebd"
android:shadowRadius="1.0"
android:shadowDx="1.0"
android:paddingLeft="20px"
android:paddingRight="25px"
android:layout_width="wrap_content" android:layout_height="wrap_content" android:textColor="#212421" android:textSize="16dp"
android:layout_below="@+id/TextView07" android:layout_toRightOf="@+id/ImageView05" android:paddingTop="20px" android:paddingBottom="20px"/>
<Button android:id="@+id/help_button2" android:layout_below="@+id/TextView08"
android:layout_width="wrap_content" android:layout_height="wrap_content"
android:layout_centerHorizontal="true" android:text="Previous" />
</RelativeLayout>
</ScrollView>
/thx in advance
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
在您写入
px
的位置更改dp
。这是android本身支持和建议的......Changes
dp
wherever you have writtenpx
. This is supported and suggested by android itself....