【发布时间】:2011-03-31 11:43:44
【问题描述】:
我对 android 中的不同分辨率有疑问。我在RelativeLayout 中编写了一个xml GUI 文件。我创建了小图片,除了图片我想要文本视图。当我更改分辨率时会出现我的问题,textviews“文本”移动,我担心这在不同的分辨率下看起来很糟糕。
我现在所做的,例如创建一个图像,在该图像的右侧创建一个文本视图,这个文本视图位于另一个图像下方,例如 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 提前
【问题讨论】:
标签: android android-layout android-relativelayout