2012-03-31 73 views
0

我有一個ImageView和2個TextView的下面的佈局,我希望他們都有相同的高度。但是,ImageView總是佔用超過一半的屏幕。任何幫助都非常令人滿意。如何設置ImageView和兩個TextviewS具有相同的高度?

這裏的佈局:

<?xml version="1.0" encoding="utf-8"?> 
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
android:layout_width="fill_parent" 
android:layout_height="fill_parent" 
android:background="#FFFFFF" 
android:orientation="vertical" > 

<ImageView android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:layout_weight="0.4" 
    android:src="@drawable/sprint" /> 
<TextView 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:layout_weight="0.3" 
    android:background="#555555" 
    android:text="@string/hello" /> 
<TextView 
    android:layout_width="fill_parent" 
    android:layout_height="wrap_content" 
    android:layout_weight="0.3" 
    android:text="@string/hello" /> 

</LinearLayout> 
+0

什麼是圖像的尺寸? – 2012-03-31 17:21:34

+0

你想讓textviews具有相同的高度還是全部具有相同的高度? – Squazic 2012-03-31 17:22:42

+0

@Win Myo Htet圖像是753像素高* 401像素寬度 – 2012-03-31 17:23:25

回答

0

你將不得不設置

android:layout_width="fill_parent" and android:layout_weight="1" 

以下是這可能會幫助你的鏈接。 LINK

+0

感謝您的鏈接幫助了我很多。技巧是設置android:layout_weight =「1」和android:layout_height =「0dp」 – 2012-03-31 17:37:51

0

嘗試

android:layout_weight="1" 

所有三個,請確保您的圖片尺寸不超過您爲它爭回空間中定義的大。

0

試試這幾個小的變化...

<ImageView android:layout_width="wrap_content" 
    android:layout_height="fill_parent" 
    android:layout_weight="1" 
    android:src="@drawable/sprinklicious" /> 
<TextView 
    android:layout_width="wrap_content" 
    android:layout_height="fill_parent" 
    android:layout_weight="1" 
    android:background="#555555" 
    android:text="@string/hello" /> 
<TextView 
    android:layout_width="wrap_parent" 
    android:layout_height="fill_parent" 
    android:layout_weight="1" 
    android:text="@string/hello" /> 

</LinearLayout> 
+0

它沒有工作。 :( – 2012-03-31 17:29:36

+0

在圖像視圖中將src更改爲背景並嘗試 – Ishu 2012-03-31 17:36:53

+0

謝謝Dilse。最後,它工作正常;) – 2012-03-31 17:40:52

相關問題