android - ImageButtons 没有对齐

标签 android android-layout

我正在尝试对齐三个 ImageButton 属性 android:layout_marginLeft="10dp" 正在工作但是 android:layout_marginBottom="10dp" 不工作,我不是能够找出问题,请任何人帮助我...提前致谢

activity_main.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="@android:color/transparent"
    tools:context=".MainActivity" >

<fragment
    android:id="@+id/map_fragment"
    android:name="com.google.android.gms.maps.SupportMapFragment"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_alignParentBottom="true"
    android:layout_alignParentRight="true"
    android:layout_alignParentTop="true" />

<RelativeLayout
    android:id="@+id/relativeLayout1"
    android:layout_width="350dp"
    android:layout_height="40dp"
    android:layout_marginLeft="15dp"
    android:layout_marginRight="15dp"
    android:layout_marginTop="20dp"
    android:background="@drawable/card_for_edittext" >

    <ImageButton
        android:id="@+id/button_go"
        android:layout_width="50dp"
        android:layout_height="wrap_content"
        android:layout_alignParentRight="true"
        android:background="@android:color/transparent"
        android:contentDescription="@string/save_button"
        android:src="@drawable/ic_save" />

    <View
        android:layout_width="0.5dp"
        android:layout_height="20dp"
        android:layout_alignBottom="@+id/button_go"
        android:layout_marginBottom="9dp"
        android:layout_marginLeft="15dp"
        android:layout_toLeftOf="@+id/button_go"
        android:background="@android:color/darker_gray" />

    <EditText
        android:id="@+id/enteraddress"
        android:layout_width="wrap_content"
        android:layout_height="match_parent"
        android:layout_alignParentLeft="true"
        android:layout_alignParentTop="true"
        android:layout_marginLeft="5dp"
        android:background="@android:color/transparent"
        android:ems="10"
        android:hint="@string/enter_address" >
    </EditText>
</RelativeLayout>

<ImageButton
    android:id="@+id/btnCurrentLocation"
    android:layout_width="48dp"
    android:layout_height="48dp"
    android:layout_alignParentBottom="true"
    android:layout_alignParentLeft="true"
    android:layout_marginBottom="10dp"
    android:layout_marginLeft="10dp"
    android:background="@drawable/box_96"
    android:contentDescription="@string/mapView_Button"
    android:src="@drawable/ic_current_location" />

<ImageButton
    android:id="@+id/btnRefresh"
    android:layout_width="48dp"
    android:layout_height="48dp"
    android:layout_alignParentBottom="true"
    android:layout_centerHorizontal="true"
    android:layout_marginBottom="14dp"
    android:background="@drawable/box_96"
    android:contentDescription="@string/refresh_button"
    android:src="@drawable/ic_refresh"
    android:text="@string/refresh_button" />

<ImageButton
    android:id="@+id/btnListview"
    android:layout_width="48dp"
    android:layout_height="48dp"
    android:layout_alignParentBottom="true"
    android:layout_alignParentRight="true"
    android:background="@drawable/box_96"
    android:contentDescription="@string/mapView_Button"
    android:src="@drawable/ic_location_list" />

</RelativeLayout>

最佳答案

你忘了加

android:layout_marginBottom="14dp"

在最后一个 ImageButton

你的代码。 :

<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="@android:color/transparent"
    tools:context=".MainActivity" >

<fragment
    android:id="@+id/map_fragment"
    android:name="com.google.android.gms.maps.SupportMapFragment"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_alignParentBottom="true"
    android:layout_alignParentRight="true"
    android:layout_alignParentTop="true" />

<RelativeLayout
    android:id="@+id/relativeLayout1"
    android:layout_width="350dp"
    android:layout_height="40dp"
    android:layout_marginLeft="15dp"
    android:layout_marginRight="15dp"
    android:layout_marginTop="20dp"
    android:background="@drawable/card_for_edittext" >

    <ImageButton
        android:id="@+id/button_go"
        android:layout_width="50dp"
        android:layout_height="wrap_content"
        android:layout_alignParentRight="true"
        android:background="@android:color/transparent"
        android:contentDescription="@string/save_button"
        android:src="@drawable/ic_save" />

    <View
        android:layout_width="0.5dp"
        android:layout_height="20dp"
        android:layout_alignBottom="@+id/button_go"
        android:layout_marginBottom="9dp"
        android:layout_marginLeft="15dp"
        android:layout_toLeftOf="@+id/button_go"
        android:background="@android:color/darker_gray" />

    <EditText
        android:id="@+id/enteraddress"
        android:layout_width="wrap_content"
        android:layout_height="match_parent"
        android:layout_alignParentLeft="true"
        android:layout_alignParentTop="true"
        android:layout_marginLeft="5dp"
        android:background="@android:color/transparent"
        android:ems="10"
        android:hint="@string/enter_address" >
    </EditText>
</RelativeLayout>

<ImageButton
    android:id="@+id/btnCurrentLocation"
    android:layout_width="48dp"
    android:layout_height="48dp"
    android:layout_alignParentBottom="true"
    android:layout_alignParentLeft="true"
    android:layout_marginBottom="14dp"
    android:layout_marginLeft="10dp"
    android:background="@drawable/box_96"
    android:contentDescription="@string/mapView_Button"
    android:src="@drawable/ic_current_location" />

<ImageButton
    android:id="@+id/btnRefresh"
    android:layout_width="48dp"
    android:layout_height="48dp"
    android:layout_alignParentBottom="true"
    android:layout_centerHorizontal="true"
    android:layout_marginBottom="14dp"
    android:background="@drawable/box_96"
    android:contentDescription="@string/refresh_button"
    android:src="@drawable/ic_refresh"
    android:text="@string/refresh_button" />

<ImageButton
    android:id="@+id/btnListview"
    android:layout_width="48dp"
    android:layout_height="48dp"
    android:layout_alignParentBottom="true"
    android:layout_alignParentRight="true"
    android:layout_marginBottom="14dp"
    android:layout_marginRight="10dp"
    android:background="@drawable/box_96"
    android:contentDescription="@string/mapView_Button"
    android:src="@drawable/ic_location_list" />

</RelativeLayout>

关于android - ImageButtons 没有对齐,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20604513/

相关文章:

android - 相对于另一个按钮的弹出对话框

Android OneDrive SDK 显示磁盘容量

Android - 为什么自动链接会忽略 URL 的根路径?

android - 如何禁用涟漪效应?

java - Android:扫描获取 WiFi 列表 - ListView 未出现

java - R.java 文件中的语法错误

Android - 键盘显示在 Activity 下方而不是 Activity 上方

android-layout - "end edge"、 "right edge"、 "toEndOf"、 "toRightOf"之间的XML Android差异

android - 一个简单的线性布局是否回收它的 subview ?

android - 对齐 2 个 View 底部,但一个被进一步推低