2013-12-23 164 views
1

我使用LinearLayout來水平堆疊4個圖像,除了高度以外,它工作良好。看起來linearlayout沒有正確包裝其內容。如果我沒有將圖像的縮放類型設置爲fitStart,它們將位於linearlayout內部。LinearLayout不包裝內容

這裏是我下面的佈局:

linearlayout

<LinearLayout 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:layout_gravity="top" 
    android:orientation="horizontal" 
    android:weightSum="4" 
    android:layout_marginLeft="40dp" 
    android:layout_marginRight="40dp"> 

    <ImageView 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:id="@+id/imageView" 
     android:src="@drawable/header1" 
     android:layout_weight="1" 
     android:scaleType="fitStart" /> 

    <ImageView 
     android:layout_width="fill_parent" 
     android:layout_height="wrap_content" 
     android:id="@+id/imageView2" 
     android:layout_gravity="center_vertical" 
     android:src="@drawable/header2" 
     android:layout_weight="1" 
     android:scaleType="fitStart" /> 

    <ImageView 
     android:layout_width="fill_parent" 
     android:layout_height="wrap_content" 
     android:id="@+id/imageView3" 
     android:layout_gravity="center_vertical" 
     android:src="@drawable/header3color" 
     android:layout_weight="1" 
     android:scaleType="fitStart" /> 

    <ImageView 
     android:layout_width="fill_parent" 
     android:layout_height="wrap_content" 
     android:id="@+id/imageView4" 
     android:src="@drawable/header4" 
     android:layout_weight="1" 
     android:scaleType="fitStart" /> 
</LinearLayout> 
+0

請不要切斷XML。我們需要更多地瞭解這個問題。 –

回答

3

嘗試這些圖像的adjustViewBounds屬性設置爲truehttp://developer.android.com/reference/android/widget/ImageView.html#attr_android:adjustViewBounds

這應該照顧你有額外的空間和LinearLayout應該wrap_content正確。

+0

嗯,不起作用... – danieljohngomez

+0

哎呀,我把錯誤的屬性放在我的答案中。只需修復它,所以請嘗試adjustViewBounds –

+0

它的工作原理!我在想這個屬性是錯誤的。在5分鐘內我不能接受這個答案:)謝謝! – danieljohngomez

2

嘗試增加android:adjustViewBounds="true"ImageView小號

+0

感謝您也:) – danieljohngomez

-1
android:adjustViewBounds="true" to be set in your imageview's