2013-12-16 48 views
2

我試圖排列至少三ImageButton的屬性android:layout_marginLeft="10dp"是工作,但android:layout_marginBottom="10dp"不工作,我無法找出問題,請人幫助我...在此先感謝ImageButtons沒有得到一致

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> 

回答

2

你忘了在最後加

android:layout_marginBottom="14dp"

你的代碼。 :

<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> 
+0

感謝您通知... eclipse不會在圖形佈局中顯示應用或更改的參數,雖然我可以在真實設備上看到這些更改 –

+0

@RBM的樂趣。 :) – SilentKiller

0

你需要保持android:layout_marginBottom arrtibut = 10 DP所有這樣的3個按鍵:

<ImageButton 
    android:id="@+id/btnCurrentLocation" 
    ...other attributes... 
    android:layout_marginBottom="10dp" 
    ...other attributes... /> 

<ImageButton 
    android:id="@+id/btnRefresh" 
    ...other attributes... 
    android:layout_marginBottom="10dp" 
    ...other attributes.../> 

<ImageButton 
    android:id="@+id/btnListview" 
    ...other attributes... 
    android:layout_marginBottom="10dp" 
    ...other attributes... /> 

你一直10dp只爲第一個按鈕,14dp的第二個按鈕,並沒有爲第3個按鈕指定layout_marginBottom。 您應該爲所有3個按鈕添加10dp