如何设置ImageView和两个TextviewS具有相同的高度?

时间:2012-03-31 17:16:08

标签: java android xml android-layout

我有一个ImageView和2个TextView的以下布局,我希望它们都具有相同的高度。但是,ImageView总是占据屏幕的一半以上。任何帮助都是非常苛刻的。

这是布局:

<?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>

3 个答案:

答案 0 :(得分:0)

尝试

android:layout_weight="1"

对于所有三个,请确保您的图像尺寸不大于您为其分配的空间定义的图像尺寸。

答案 1 :(得分:0)

您必须设置

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

以下是可能对您有所帮助的链接。 LINK

答案 2 :(得分: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>