0

我是 Android 编程的新手,我已经尝试过彻底研究,但仍然不太了解如何解决这个问题。我将在下面包含我的 XML 代码。我尝试在 Eclipse 的相对布局中使用设置“dip”大小来获得我的应用程序所需的外观。简单的布局 - 标题标题和中间的 3 个按钮。显然,我遇到的问题是由于设置的特定尺寸而尴尬地拉伸所有东西。关于如何在此处正确使用“match_parent”和“wrap_content”的任何建议?我只是不太了解如何在这种情况下应用它们。也许我应该使用线性布局,但相对布局似乎是更好的选择,以防我将来将按钮数从 3 个增加到 9 个以上以提高性能。任何帮助深表感谢!

这是我的 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:orientation="vertical"
tools:context=".MainActivity"
android:background="#ffffff" >

<TextView
    android:id="@+id/textView1"
    android:layout_width="match_parent"
    android:layout_height="60dip"
    android:layout_alignParentTop="true"
    android:layout_centerHorizontal="true"
    android:background="@drawable/pets_titlecrop" />

<Button
    android:id="@+id/button1"
    android:layout_width="80dip"
    android:layout_height="80dip"
    android:layout_below="@+id/textView1"
    android:layout_centerHorizontal="true"
    android:layout_marginTop="48dp"
    android:background="@drawable/call_now" />"


<TextView
    android:id="@+id/textView2"
    android:layout_width="100dip"
    android:layout_height="wrap_content"
    android:layout_alignParentBottom="true"
    android:layout_alignParentLeft="true"
    android:layout_below="@+id/textView1"
    android:background="#808080" />

<TextView
    android:id="@+id/textView3"
    android:layout_width="100dip"
    android:layout_height="wrap_content"
    android:layout_alignParentBottom="true"
    android:layout_alignParentRight="true"
    android:layout_alignTop="@+id/textView2"
    android:background="#808080" />"



<Button
    android:id="@+id/button3"
    android:layout_width="80dip"
    android:layout_height="80dip"
    android:layout_alignLeft="@+id/button2"
    android:layout_below="@+id/button2"
    android:layout_marginTop="36dp"
    android:background="@drawable/bpaw_printedit" />

<Button
    android:id="@+id/button2"
    android:layout_width="80dip"
    android:layout_height="80dip"
    android:layout_alignLeft="@+id/button1"
    android:layout_below="@+id/button1"
    android:layout_marginTop="36dp"
    android:background="@drawable/blue_globemap" />

<TextView
    android:id="@+id/textView5"
    android:layout_width="100dip"
    android:layout_height="30dip"
    android:layout_alignParentBottom="true"
    android:layout_toLeftOf="@+id/textView3"
    android:layout_toRightOf="@+id/textView2"
    android:background="@drawable/by_wvg" />



 </RelativeLayout>
4

1 回答 1

0

您应该尝试嵌套线性布局,因此使用权重可以实现灵活的用户界面,试试这个

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:id="@+id/LinearLayout1"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:background="#ffffff"
    android:orientation="vertical"
    tools:context=".MainActivity" >

<TextView
    android:id="@+id/textView1"
    android:layout_width="match_parent"
    android:layout_height="60dip" />

<LinearLayout
    android:layout_width="match_parent"
    android:layout_height="match_parent" >

    <TextView
        android:id="@+id/textView3"
        android:layout_width="0dp"
        android:layout_height="match_parent"
        android:layout_weight="1"
        android:background="#808080" />

    <LinearLayout
        android:layout_width="0dp"
        android:layout_height="match_parent"
        android:layout_weight="1"
        android:orientation="vertical" >

        <Button
            android:id="@+id/button1"
            android:layout_width="match_parent"
            android:layout_height="0dp"
            android:layout_weight="1" />

        <Button
            android:id="@+id/button2"
            android:layout_width="match_parent"
            android:layout_height="0dp"
            android:layout_weight="1" />

        <Button
            android:id="@+id/button3"
            android:layout_width="match_parent"
            android:layout_height="0dp"
            android:layout_weight="1" />

        <TextView
            android:id="@+id/textView5"
            android:layout_width="match_parent"
            android:layout_height="0dp"
            android:layout_weight="1" />

    </LinearLayout>

    <TextView
        android:id="@+id/textView2"
        android:layout_width="0dp"
        android:layout_height="match_parent"
        android:layout_weight="1"
        android:background="#808080" />

</LinearLayout>

于 2013-08-27T19:44:38.283 回答