2014-05-12 29 views
0

我試圖做一個底部佈局,如圖像中1獲取底部佈局的扭曲佈局

correct image

但是,當應用程序的工作,底部佈局被拉長大屏幕上像圖2: incorrect image

這裏是源...

<RelativeLayout 
    android:id="@+id/bottom_layout" 
    android:layout_width="fill_parent" 
    android:layout_height="wrap_content" 
    android:background="@layout/footer_color" 
    android:layout_alignParentBottom="true"> 
<LinearLayout 
    android:id="@+id/bottom_layout1" 
    android:layout_width="fill_parent" 
    android:layout_height="wrap_content" 
    android:weightSum="1.0" 
    android:orientation="horizontal"> 

<Button 
    android:id="@+id/bottom_layout11" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:layout_weight="0.2" 
    android:gravity="center" 
    android:background="@drawable/profile_01"/> 
<Button 
    android:id="@+id/bottom_layout12" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:gravity="center" 
    android:layout_weight="0.2" 
    android:background="@drawable/profile_01"/> 
<Button 
    android:id="@+id/bottom_layout13" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:layout_weight="0.2" 
    android:gravity="center" 
    android:background="@drawable/profile_01"/> 
<Button 
    android:id="@+id/bottom_layout14" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:layout_weight="0.2" 
    android:gravity="center" 
    android:background="@drawable/profile_01"/> 
    <Button 
    android:id="@+id/bottom_layout15" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:layout_weight="0.2" 
    android:gravity="center" 
    android:background="@drawable/profile_01"/> 

    </LinearLayout> 
    </RelativeLayout> 

須─頁腳佈局與在所有分辨率下沒有拉伸都有相同的空間。

我沒有得到我應該在哪裏改進代碼。請回復 。

在此先感謝。

+0

你爲什麼要硬編碼相對佈局的高度50dp..let它被WRAP_CONTENT和公正使用合適大小的圖像.. – Vikram

+0

給出相同的結果@Vikram –

+0

請參閱更新的1 ... –

回答

1
// try this way,hope this will help you... 

Note : please put respective images on all size drawable folder. 

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:id="@+id/bottom_layout" 
    android:layout_width="match_parent" 
    android:layout_height="wrap_content" 
    android:background="@layout/footer_color" 
    android:layout_alignParentBottom="true"> 

    <LinearLayout 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content"> 
     <LinearLayout 
      android:layout_width="0dp" 
      android:layout_height="wrap_content" 
      android:layout_weight="1" 
      android:gravity="center"> 
      <Button 
       android:id="@+id/bottom_layout11" 
       android:layout_width="wrap_content" 
       android:layout_height="wrap_content" 
       android:background="@drawable/profile_01"/> 
     </LinearLayout> 
     <LinearLayout 
      android:layout_width="0dp" 
      android:layout_height="wrap_content" 
      android:layout_weight="1" 
      android:gravity="center"> 
      <Button 
       android:id="@+id/bottom_layout12" 
       android:layout_width="wrap_content" 
       android:layout_height="wrap_content" 
       android:background="@drawable/profile_01"/> 
     </LinearLayout> 
     <LinearLayout 
      android:layout_width="0dp" 
      android:layout_height="wrap_content" 
      android:layout_weight="1" 
      android:gravity="center"> 
      <Button 
       android:id="@+id/bottom_layout13" 
       android:layout_width="wrap_content" 
       android:layout_height="wrap_content" 
       android:background="@drawable/profile_01"/> 
     </LinearLayout> 
     <LinearLayout 
      android:layout_width="0dp" 
      android:layout_height="wrap_content" 
      android:layout_weight="1" 
      android:gravity="center"> 
      <Button 
       android:id="@+id/bottom_layout14" 
       android:layout_width="wrap_content" 
       android:layout_height="wrap_content" 
       android:background="@drawable/profile_01"/> 
     </LinearLayout> 
     <LinearLayout 
      android:layout_width="0dp" 
      android:layout_height="wrap_content" 
      android:layout_weight="1" 
      android:gravity="center"> 
      <Button 
       android:id="@+id/bottom_layout15" 
       android:layout_width="wrap_content" 
       android:layout_height="wrap_content" 
       android:background="@drawable/profile_01"/> 
     </LinearLayout> 
    </LinearLayout> 
</RelativeLayout> 
+0

感謝哥們@Haresh –

1

如果你想支持不同的屏幕,那麼你需要根據屏幕提供圖像和值。

爲每個屏幕尺寸創建valuesdrawable。如果您想使用自定義,請在值文件夾中指定您的高度和寬度,否則請將其設置爲match_parentwrap_content

您需要創建四個文件夾

values-ldpi // Small Screens 
values-mdpi // Medium Screens 
values-hdpi // Large Screens 
values-xhdpi // Xtra Large Screens 

而且你需要使用正確的圖像大小。對於大小請Android Support Mulitple Screens

+0

我知道這個,但我該怎麼辦,因爲問題(不同的方法...嗯,我猜)... –

1

試試這個代碼:

<RelativeLayout 
    android:id="@+id/bottom_layout" 
    android:layout_width="fill_parent" 
    android:layout_height="wrap_content" 
    android:background="@layout/footer_color" 
    android:layout_alignParentBottom="true"> 
<LinearLayout 
    android:id="@+id/bottom_layout1" 
    android:layout_width="fill_parent" 
    android:layout_height="wrap_content" 
    android:weightSum="1.0" 
    android:orientation="horizontal"> 
    <LinearLayout 
     android:layout_width="0dp" 
     android:layout_height="wrap_content" 
     android:weightSum="0.2" 
     > 
    <Button 
     android:id="@+id/bottom_layout11" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:gravity="center" 
     android:background="@drawable/profile_01"/> 
    </LinearLayout> 
    <LinearLayout 
     android:layout_width="0dp" 
     android:layout_height="wrap_content" 
     android:weightSum="0.2" 
     > 
    <Button 
     android:id="@+id/bottom_layout12" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:gravity="center" 
     android:background="@drawable/profile_01"/> 
    </LinearLayout> 
    <LinearLayout 
     android:layout_width="0dp" 
     android:layout_height="wrap_content" 
     android:weightSum="0.2" 
     > 
    <Button 
     android:id="@+id/bottom_layout13" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:gravity="center" 
     android:background="@drawable/profile_01"/> 
    </LinearLayout> 
    <LinearLayout 
     android:layout_width="0dp" 
     android:layout_height="wrap_content" 
     android:weightSum="0.2" 
     > 
    <Button 
     android:id="@+id/bottom_layout14" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:gravity="center" 
     android:background="@drawable/profile_01"/> 
    </LinearLayout> 
    <LinearLayout 
     android:layout_width="0dp" 
     android:layout_height="wrap_content" 
     android:weightSum="0.2" 
     > 
     <Button 
     android:id="@+id/bottom_layout15" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:gravity="center" 
     android:background="@drawable/profile_01"/> 
     </LinearLayout> 
     </LinearLayout> 
     </RelativeLayout> 

共享輸出..