2012-02-01 56 views
0

我的圖像按鈕是40px的高度,但我的畫廊是高度很大。現在,我的圖像按鈕佔據了它們的整個空間,並且與我的畫廊高度相同。在保持這種水平佈局的同時,是否有按鈕保持原有尺寸?LinearLayout與layout_weights與高度不同的孩子

<LinearLayout 
     android:layout_width="match_parent" 
     android:layout_height="match_parent" 
     android:gravity="center" 
     android:orientation="horizontal" 
     android:paddingTop="20dp" > 

     <ImageButton 
      android:id="@+id/left_arrow" 
      android:layout_weight="3" 
      android:layout_width="match_parent" 
      android:layout_height="match_parent" 
      android:background="@drawable/shared_arrow_left_button_selector" 
      android:scaleType="fitCenter" /> 

     <Gallery 
      android:id="@+id/gallery" 
      android:focusable="true" 
     android:focusableInTouchMode="true" 
     android:layout_weight="1" 
      android:layout_width="match_parent" 
      android:layout_height="wrap_content" 
      android:spacing="15dp" /> 

     <ImageButton 
      android:id="@+id/right_arrow" 
      android:layout_weight="3" 
      android:layout_width="match_parent" 
      android:layout_height="match_parent" 
      android:background="@drawable/shared_arrow_right_button_selector" 
      android:scaleType="fitCenter" /> 
    </LinearLayout> 
+1

您能否請您添加LinearLayout的開始標籤,以便我能更好地理解它? – Badal 2012-02-01 05:00:47

+0

更新與你正在獲得的屏幕截圖... – MKJParekh 2012-02-01 05:12:40

回答

0

你申請

android:layout_width="match_parent" 
android:layout_height="match_parent" 

到兩個ImageButtons所以他們正在填補的高度,如果你只是想ImageButtons來包裝他們的原始大小隻是改變他們wrap_content並刪除layout_weight屬性。此外,當您將layout_weight="1"應用於圖庫時,只需更改android:layout_width="0dp",因爲寬度將由layout_weight屬性本身管理。您的最終佈局應該是這樣的,

<?xml version="1.0" encoding="utf-8"?> 
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    android:gravity="center" 
    android:orientation="horizontal" 
    android:paddingTop="20dp" > 

    <ImageButton 
     android:id="@+id/left_arrow" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:scaleType="fitCenter" /> 

    <Gallery 
     android:id="@+id/gallery" 
     android:layout_width="0dp" 
     android:layout_height="wrap_content" 
     android:layout_weight="1" 
     android:focusable="true" 
     android:focusableInTouchMode="true" 
     android:spacing="15dp" /> 

    <ImageButton 
     android:id="@+id/right_arrow" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:scaleType="fitCenter" /> 

</LinearLayout> 
0

刪除ImageButtons中的佈局權重= 3,這是顯示圖像按鈕比圖庫大的原因。

我認爲你不知道如何使用layout_weight屬性,以便你不知道如何解決這個問題。首先了解layout_weight。

如果您有任何疑問隨時問我。

在圖像按鈕和圖庫中使用下面的行,它會很好。

android:layout_weight="1" 
android:layout_width="match_parent" 
android:layout_height="wrap_content" 
+0

我認爲重量動態地調整大小的意見寬度 – Raptrex 2012-02-01 05:23:57

0
<ImageButton 
     android:id="@+id/left_arrow" 
     android:layout_weight="3" 
     android:layout_width="match_parent" 
     android:layout_height="match_parent" 
     android:background="@drawable/shared_arrow_left_button_selector" 
     android:scaleType="centerinside" /> 
Remove Weight attribute, and set width and height of buttons to wrap_content 
    <Gallery 
     android:id="@+id/gallery" 
     android:focusable="true" 
    android:focusableInTouchMode="true" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:spacing="15dp" /> 

    <ImageButton 
     android:id="@+id/right_arrow" 
     android:layout_weight="3" 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:background="@drawable/shared_arrow_right_button_selector" 
     android:scaleType="centerinside" /> 
</LinearLayout>