0

我创建了小、正常、大和 xl 布局,当我运行代码时,这是两者都是正常屏幕尺寸时的结果。如果我修复一个,另一个就会搞砸,反之亦然。他们是解决这个问题的另一种方法还是如何解决。

宏达一V 宏达一V

三星S3 三星 3

普通布局的代码

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:id="@+id/layout"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:background="@drawable/background1"
    android:gravity="fill_vertical"
    android:paddingBottom="@dimen/activity_vertical_margin"
    android:paddingLeft="@dimen/activity_horizontal_margin"
    android:paddingRight="@dimen/activity_horizontal_margin"
    android:paddingTop="@dimen/activity_vertical_margin"
    tools:context=".MainActivity" >

    <ImageView
        android:id="@+id/imageView1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_above="@+id/seekBar1"
        android:layout_alignParentLeft="true"
        android:layout_alignParentRight="true"
        android:layout_alignParentTop="true"
        android:src="@drawable/pumpkin" />

    <ImageButton
        android:id="@+id/imageButton2"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_marginLeft="500dp"
        android:layout_marginTop="150dp"
        android:background="@null"
        android:src="@drawable/righteyeoff" />

    <SeekBar
        android:id="@+id/seekBar1"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_alignLeft="@+id/imageView1"
        android:layout_alignParentBottom="true"
        android:thumb="@drawable/skull" />

    <ImageButton
        android:id="@+id/imageButton1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_marginLeft="350dp"
        android:layout_marginTop="150dp"
        android:background="@null"
        android:src="@drawable/lefteyeoff" />

</RelativeLayout>
4

2 回答 2

0

我发现使用 Android 将对象/图像放在彼此之上非常困难。

我会把事情放在绝对中心。

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/RelativeLayout01"
android:layout_width="fill_parent"
android:layout_height="fill_parent">

对于我会使用的图像

  <ImageView
    android:id="@+id/main_pic"
    android:layout_width="xxdip or wrap_content "
    android:layout_height="xxdip or wrap_content"
    android:layout_centerHorizontal="true"
    android:layout_centerVertical="true">

并将一些放在其他上面。也许眼睛(仍处于相对布局中)在鼻子上方呈线性布局。

祝你好运!

于 2013-10-22T22:27:10.483 回答
0

您还可以使用框架/线性布局。我仍在使用 dp,但数量较少,这减少了您所看到的巨大差异。我希望你仍然明白这个想法,我没有你的图像可以使用,所以只使用了颜色。在此示例中,您应该使用 wrap_content 而不是设置的宽度/高度。

<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools" android:id="@+id/layout" android:layout_width="match_parent" android:layout_height="match_parent" tools:context=".MainActivity" android:padding="20dp">
    <LinearLayout android:id="@+id/pumpkin" android:layout_width="200dp" android:layout_height="200dp" android:layout_gravity="center" android:gravity="center" android:background="@android:color/black">
        <ImageView android:id="@+id/leftEye" android:orientation="horizontal" android:layout_width="20dp" android:layout_height="20dp" android:layout_marginBottom="30dp" android:layout_marginRight="20dp" android:src="@android:color/holo_orange_dark" />
        <ImageView android:id="@+id/rightEye" android:orientation="horizontal" android:layout_width="20dp" android:layout_height="20dp" android:layout_marginBottom="30dp" android:layout_marginLeft="20dp" android:src="@android:color/holo_orange_dark" />
    </LinearLayout>
    <SeekBar android:id="@+id/seekBar1" android:layout_gravity="bottom" android:layout_width="match_parent" android:layout_height="wrap_content" />
</FrameLayout>
于 2013-10-22T22:56:12.183 回答