2011-08-30 107 views
0

在我的應用程序中,我使用相對佈局design.in一個活動我有四個按鈕在屏幕的底部。我的xml代碼(Land Scape)不適合所有設備屏幕。它在按鈕之間有更多的空間,如圖所示。如何設計適合所有分辨率屏幕(橫向)的佈局。Android中的相對佈局問題

佈局圖像是: enter image description here

我的XML:

<RelativeLayout android:id="@+id/relativeLayout1" 
android:layout_width="fill_parent" android:layout_height="fill_parent" 
android:background="#0000FF" 
xmlns:android="http://schemas.android.com/apk/res/android"> 


<RelativeLayout android:layout_width="fill_parent" 
    android:layout_gravity="bottom" android:layout_alignParentBottom="true" 
    android:background="@drawable/applicarion_bar" android:layout_height="wrap_content" 
    android:id="@+id/relativeLayout4"> 

     <ImageButton android:id="@+id/homeimageButton2" 
      android:layout_alignParentLeft="true" 
      android:layout_width="wrap_content" android:layout_height="wrap_content" 
      android:background="@drawable/festival_btn" /> 

     <ImageButton android:layout_height="wrap_content" 
      android:layout_toRightOf="@+id/homeimageButton2" 
      android:layout_marginLeft="60dp" 
      android:layout_width="wrap_content" android:background="@drawable/search_btn" 
      android:id="@+id/homeimageButton3"></ImageButton> 
     <TextView android:id="@+id/homecalendar4" android:text="MAR 20" 
      android:layout_toRightOf="@+id/homeimageButton3" 
      android:gravity="center" 
      android:textSize="10dp" 
      android:layout_marginLeft="60dp" 
      android:layout_width="wrap_content" android:layout_height="wrap_content" 
      android:background="@drawable/calendar_btn" /> 
     <ImageButton android:id="@+id/homeimageButton5" 
      android:layout_alignParentRight="true" 
      android:layout_marginLeft="10dp" 
      android:layout_width="wrap_content" android:layout_height="wrap_content" 
      android:background="@drawable/favorite_btn" /> 

</RelativeLayout> 

+0

而不是RelativeLayout,你可以使用Linearlayout? – Venky

回答

1

更換你relativeLayout4爲

<LinearLayout android:id="@+id/put_id_of_ll" 
     android:orientation="horizontal" android:background="#012C58" 
     android:paddingLeft="4.0dip" android:paddingTop="5.0dip" 
     android:paddingRight="4.0dip" android:paddingBottom="1.0dip" 
     android:layout_width="fill_parent" android:layout_height="wrap_content" 
     android:layout_alignParentBottom="true"> 
       <ImageButton android:id="@+id/homeimageButton2" 
       android:layout_width="0.0dip" 
       android:text="ImageButton" 
       android:background="@drawable/festival_btn" 
       android:layout_weight="1.0" 
       android:layout_height="wrap_content" 
       android:padding="10dp" 
       android:layout_marginBottom="3dip" 
       android:layout_marginLeft="2dip" /> 
      <ImageButton android:id="@+id/homeimageButton3"  
android:background="@drawable/search_btn" 
       android:layout_width="0.0dip" 
       android:text="btn2" 
       android:layout_weight="1.0" 
       android:layout_height="wrap_content" 
       android:padding="10dp" 
       android:layout_marginBottom="3dip" 
       android:layout_marginLeft="2dip" /> 
      <TextView android:id="@+id/homecalendar4" android:text="MAR 20" 
       android:layout_width="0.0dip" 
       android:layout_weight="1.0" 
       android:layout_height="wrap_content" 
       android:padding="10dp" 
       android:layout_marginBottom="3dip" 
       android:layout_marginLeft="2dip" /> 
      <ImageButton android:id="@+id/homeimageButton5" 
       android:layout_width="0.0dip" 
       android:text="btn4" 
       android:background="@drawable/favorite_btn" 
       android:layout_weight="1.0" 
       android:layout_height="wrap_content" 
       android:padding="10dp" 
       android:layout_marginBottom="3dip" 
       android:layout_marginLeft="2dip" /> 
     </LinearLayout> 

它將工作。

編碼愉快:)

+0

謝謝,並延遲 –

+0

@murali_ma歡迎!並嘗試提出答案,這對我們有好處。 :) –

0

使用線性佈局而不是相對佈局,使用下面碼

<RelativeLayout android:id="@+id/relativeLayout1" 
android:layout_width="fill_parent" android:layout_height="fill_parent" 
android:background="#0000FF" 
xmlns:android="http://schemas.android.com/apk/res/android"> 


<LinearLayout android:layout_width="fill_parent" 
    android:layout_gravity="bottom" android:orientation="horizontal" 
    android:background="@drawable/applicarion_bar" android:layout_height="wrap_content" 
    android:id="@+id/relativeLayout4"> 

     <ImageButton android:id="@+id/homeimageButton2" 
      android:layout_alignParentLeft="true" 
      android:layout_width="wrap_content" android:layout_height="wrap_content" 
      android:layout_weight="1" 
      android:background="@drawable/festival_btn" /> 

     <ImageButton android:layout_height="wrap_content" 
      android:layout_toRightOf="@+id/homeimageButton2" 
      android:layout_weight="1" 
      android:layout_marginLeft="60dp" 
      android:layout_width="wrap_content" android:background="@drawable/search_btn" 
      android:id="@+id/homeimageButton3"></ImageButton> 

     <TextView android:id="@+id/homecalendar4" android:text="MAR 20" 
      android:layout_toRightOf="@+id/homeimageButton3" 
      android:gravity="center" 
      android:textSize="10dp" 
      android:layout_marginLeft="60dp" 
      android:layout_weight="1" 
      android:layout_width="wrap_content" android:layout_height="wrap_content" 
      android:background="@drawable/calendar_btn" /> 

     <ImageButton android:id="@+id/homeimageButton5" 
      android:layout_alignParentRight="true" 
      android:layout_marginLeft="10dp" 
      android:layout_weight="1" 
      android:layout_width="wrap_content" android:layout_height="wrap_content" 
      android:background="@drawable/favorite_btn" /> 

</LinearLayout> 

</RelativeLayout> 
0

嘗試使用線性佈局,所有的觀點給予同等權重。