-1

好的,这个问题已经困扰了我大约 2 周了,通过我所做的所有研究,我仍然无法弄清楚这一点。我有 6 个饼图形式的按钮。当我在 XML 中进行布局时,我可以让它们看起来很好。

我想要实现的视图

当我将其更改为平板电脑尺寸或其他尺寸的屏幕时,我的所有按钮都会移动并且看起来很糟糕。

不好的看法

如何使这些按钮在任何屏幕尺寸上保持静止?我知道我必须在适当的文件夹中有不同的图像大小,我打算这样做,但我需要知道是否有办法将这些图像锁定在 XML 文件中的某个位置,或者我需要做什么来使其正常工作。一如既往,非常感谢任何和所有帮助,如果我对我的问题不够清楚,我会回答任何问题。谢谢

这是我的 XML

 <RelativeLayout 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:background="@drawable/mainback" >

<Button
    android:id="@+id/button1"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_alignParentLeft="true"
    android:layout_centerVertical="true"
    android:layout_marginLeft="25dp"
    android:background="@drawable/ipadcollegesm" />

<Button
    android:id="@+id/button2"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_alignBottom="@+id/button1"
    android:layout_alignRight="@+id/button1"
    android:layout_marginBottom="92dp"
    android:background="@drawable/ipadmusicsm" />

<Button
    android:id="@+id/button3"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_alignBottom="@+id/button2"
    android:layout_marginLeft="5dp"
    android:layout_toRightOf="@+id/button1"
    android:background="@drawable/ipadfamilysm" />

<Button
    android:id="@+id/button4"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_alignLeft="@+id/button3"
    android:layout_alignTop="@+id/button1"
    android:background="@drawable/ipadyouthsm" />

<Button
    android:id="@+id/button5"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_alignLeft="@+id/button4"
    android:layout_below="@+id/button3"
    android:layout_marginTop="14dp"
    android:background="@drawable/ipadlinkssm" />

<Button
    android:id="@+id/button6"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_alignBaseline="@+id/button5"
    android:layout_alignBottom="@+id/button5"
    android:layout_toLeftOf="@+id/button4"
    android:background="@drawable/ipadpodcastsm" />

 </RelativeLayout>
4

1 回答 1

2

您为每个按钮提供了固定的 dp,不同的设备具有不同的分辨率。

为了以最少的工作量在多个设备上进行这项工作,我建议添加另一个相对布局作为根,并将重力设置为中心。这样,布局总是在屏幕的中心。

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:gravity="center"
android:background="@drawable/mainback">
   <RelativeLayout 
   android:layout_width="wrap_content"
   android:layout_height="wrap_content">

      *** Your buttons would be here ***

    </RelativeLayout>
</RelativeLayout>

另一种方法是为每个屏幕尺寸创建一个尺寸文件,但上面可能是最简单的方法。

于 2012-07-29T04:09:45.013 回答