如何更有效地安排我的AXML布局?

时间:2016-10-28 07:45:49

标签: android xamarin.android

我被告知我的XML布局可怕的分层。我怎么安排它?这是我希望布局看起来像的图片:

enter image description here

是否可以将图像和 ImageButton 放在一个布局中?

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:p1="http://schemas.android.com/apk/res/android"
    p1:layout_width="match_parent"
    p1:layout_height="match_parent"
    p1:id="@+id/relativeLayout1"
    p1:background="@drawable/pickcitybackground">

  <RelativeLayout
      p1:minWidth="25px"
      p1:minHeight="25px"
      p1:layout_width="229.0dp"
      p1:layout_height="217.0dp"
      p1:id="@+id/relativeLayout2"
      p1:paddingTop="90dp"
      p1:gravity="center">

    <ImageView
        p1:src="@drawable/Pick"
        p1:layout_width="120dp"
        p1:layout_height="120dp"
        p1:id="@+id/pick"
        p1:background="#02ffffff"
        p1:scaleType="centerCrop" />
</RelativeLayout>

<RelativeLayout
    p1:minWidth="25px"
    p1:minHeight="25px"
    p1:layout_width="331.5dp"
    p1:layout_height="217dp"
    p1:id="@+id/relativeLayout3"
    p1:paddingTop="90dp"
    p1:gravity="right">
    <ImageButton
        p1:src="@drawable/austinButton"
        p1:layout_width="120dp"
        p1:layout_height="120dp"
        p1:id="@+id/austinButton"
        p1:background="#02ffffff"
        p1:scaleType="centerCrop" />
</RelativeLayout>

<RelativeLayout
    p1:minWidth="25px"
    p1:minHeight="25px"
    p1:layout_width="229dp"
    p1:layout_height="match_parent"
    p1:id="@+id/relativeLayout4"
    p1:paddingTop="15dp"
    p1:gravity="center">
    <ImageButton
        p1:src="@drawable/nashvilleButton"
        p1:layout_width="120dp"
        p1:layout_height="120dp"
        p1:id="@+id/nashvilleButton"
        p1:scaleType="centerCrop"
        p1:background="#02ffffff" />
</RelativeLayout>

<RelativeLayout
    p1:minWidth="25px"
    p1:minHeight="25px"
    p1:layout_width="331.5dp"
    p1:layout_height="match_parent"
    p1:id="@+id/relativeLayout5"
    p1:gravity="right"
    p1:paddingTop="265dp">
    <ImageButton
        p1:src="@drawable/newyorkButton"
        p1:layout_width="120dp"
        p1:layout_height="120dp"
        p1:id="@+id/newyorkButton"
        p1:background="#02ffffff"
        p1:scaleType="centerCrop" />
</RelativeLayout>

<RelativeLayout
    p1:minWidth="25px"
    p1:minHeight="25px"
    p1:layout_width="229dp"
    p1:layout_height="match_parent"
    p1:id="@+id/relativeLayout6"
    p1:gravity="center"
    p1:paddingTop="350dp">
    <ImageButton
        p1:src="@drawable/sanfranButton"
        p1:layout_width="120dp"
        p1:layout_height="120dp"
        p1:id="@+id/sanfranButton"
        p1:background="#02ffffff"
        p1:scaleType="centerCrop" />
</RelativeLayout>

<RelativeLayout
    p1:minWidth="25px"
    p1:minHeight="25px"
    p1:layout_width="331.5dp"
    p1:layout_height="match_parent"
    p1:id="@+id/relativeLayout7"
    p1:gravity="right"
    p1:paddingTop="435dp">
    <ImageButton
        p1:src="@drawable/seattleButton"
        p1:layout_width="120dp"
        p1:layout_height="120dp"
        p1:id="@+id/seattleButton"
        p1:background="#02ffffff"
        p1:scaleType="centerCrop" />
</RelativeLayout>

1 个答案:

答案 0 :(得分:0)

我从这里可以看到,你在相对布局中使用相对布局。应该可以将XML减少到只有一个相对布局。 使用android:layout_marginRight="10dp"
android:layout_marginLeft="10dp" android:layout_marginTop="10dp" android:layout_marginBottom="10dp"

安排按钮

将“10dp”值替换为您需要的值。 希望有所帮助