RelativeLayout alignParentBottom conflict with android
I'm trying to design my interface using the weight attribute in order to get a nice view on different screen sizes. Basically, I use a vertical LinearLayout containing 3 RelativeLayouts (header, content and footer). I would like the header and the footer to be 15% each and the content 70% of the height. However, when I set a widget in the header for example, with alignParentBottom="true", everything messes up. It is the same problem if I use a widget with a height="fill_parent", the header fills all the LinearLayout!
[Edit] : I use the NoActionBar theme and that seems to be related to my problem as if I change to the default theme, it fixes the problem. However, I really need to hide the ActionBar...
What I have:
What I would like to do:
The problem is that for example, I would like to position the date at the bottom of header...
Here's a simplify code for the header:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="0dp"
android:background="@drawable/fond_header"
android:layout_weight=".2" >
<TextView
android:id="@+id/dateForm"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:layout_alignParentBottom="true"
android:textSize="20sp"
android:layout_marginBottom="2dp"
android:background="@drawable/fond_date_header" />
</RelativeLayout>
here's the footer:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="0dp"
android:background="@drawable/fond_header"
android:layout_weight=".2" >
<ImageButton
android:id="@+id/retourBouton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:contentDescription="@string/menu"
android:src="@drawable/retour" />
</RelativeLayout>
and here's a simplified code of the full interface:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:weightSum="1.0" >
<include layout="@layout/header" />
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="0.6" >
</RelativeLayout>
<include layout="@layout/footer" />
</LinearLayout>
Any ideas?
Thanks by advance,
Valentin
I find it easier to read when the weights are in the same layout file, like this:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:weightSum="1.0" >
<include layout="@layout/header"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight=".2"/>
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight=".6" >
</RelativeLayout>
<include layout="@layout/footer"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight=".2" />
</LinearLayout>
In your header and footer I removed the layout_weight, and set height/width to match_parent. The main layout will override those.
Update: Added header + footer.
Header:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@android:color/darker_gray">
<TextView
android:id="@+id/dateForm"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:layout_alignParentBottom="true"
android:textSize="20sp"
android:text="Some Text"
android:layout_marginBottom="2dp"
android:textColor="@android:color/black"
android:background="@android:color/white" />
</RelativeLayout>
Footer:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@android:color/darker_gray">
<ImageButton
android:id="@+id/retourBouton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:layout_alignParentBottom="true"
android:src="@drawable/ic_launcher"
android:background="@android:color/holo_orange_light"
android:contentDescription=""/>
</RelativeLayout>
链接地址: http://www.djcxy.com/p/93176.html