So my main.xml looks like this:
<?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>
What I was trying to accomplish was to have the screen split up into three: a header and footer of equal height and a body of the remaining.
When I run this code, the headerFrameLayout ends up being the size of the footerFrameLayout+the height of the logoImage. For example: headerFrameLayout=163, logoImage=58, footerFrameLayout=105 and the bodyLinearLayout=493.
I don't understand why the header also considers the size of the photo. Any ideas?
It's not obvious, but that's just how it works. If you want a 15%, 70%, 15% distribution set each of those elements to have a height of 0dp
instead of wrap_content
.
<?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>
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.