android: layout_weight учитывает размер встроенного ImageViewer в FrameLayout - PullRequest
2 голосов
/ 19 ноября 2011

Итак, мой main.xml выглядит так:

<?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:orientation="vertical" 
android:weightSum="1">


<FrameLayout
    android:id="@+id/headerFrameLayout"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:layout_weight="0.15"
    android:background="#597eAA">

    <ImageView
        android:id="@+id/logoImage"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:background="#7ba1d1"
        android:src="@drawable/logo_conekta"/>

</FrameLayout>

<LinearLayout
    android:id="@+id/bodyLinearLayout"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:layout_weight="0.7"
    android:background="#f3f3f3"
    android:orientation="horizontal" >

</LinearLayout>

<FrameLayout
    android:id="@+id/footerFrameLayout"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:layout_weight="0.15"
    android:background="#597eAA" >
</FrameLayout>

Я пытался сделать так, чтобы экран был разделен на три части: верхний и нижний колонтитулы одинаковой высотыи тело оставшегося.

Когда я запускаю этот код, headerFrameLayout заканчивается размером footerFrameLayout + высотой logoImage.Например: headerFrameLayout = 163, logoImage = 58, footerFrameLayout = 105 и bodyLinearLayout = 493.

Я не понимаю, почему в заголовке также учитывается размер фотографии.Есть идеи?

Ответы [ 2 ]

3 голосов
/ 19 ноября 2011

Это не очевидно, но так оно и есть. Если вы хотите, чтобы распределение 15%, 70%, 15% устанавливало для каждого из этих элементов высоту 0dp вместо wrap_content.

1 голос
/ 19 ноября 2011
<?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="0dp"
android:orientation="vertical" 
android:weightSum="1">


<FrameLayout
    android:id="@+id/headerFrameLayout"
    android:layout_width="fill_parent"
    android:layout_height="0dp"
    android:layout_weight="0.15"
    android:background="#597eAA">

    <ImageView
        android:id="@+id/logoImage"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        android:background="#7ba1d1"
        android:src="@drawable/logo_conekta"/>

</FrameLayout>

<LinearLayout
    android:id="@+id/bodyLinearLayout"
    android:layout_width="fill_parent"
    android:layout_height="0dp"
    android:layout_weight="0.7"
    android:background="#f3f3f3"
    android:orientation="horizontal" >

</LinearLayout>

<FrameLayout
    android:id="@+id/footerFrameLayout"
    android:layout_width="fill_parent"
    android:layout_height="0dp"
    android:layout_weight="0.15"
    android:background="#597eAA" >
</FrameLayout>
</LinearLayout>
Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...