我尝试使用权重属性设计我的界面,以便在不同的屏幕尺寸上获得漂亮的视图。 基本上,我使用包含3个RelativeLayouts(标题,内容和页脚)的垂直LinearLayout。我希望页眉和页脚各占15%,内容高度为70%。但是,当我在标题中设置一个小部件时,使用alignParentBottom =" true",一切都搞砸了。如果我使用高度为=" fill_parent"的小部件,则会出现同样的问题,标题会填满所有的LinearLayout!
[编辑]:我使用NoActionBar主题,这似乎与我的问题有关,好像我改为默认主题,它解决了问题。但是,我真的需要隐藏ActionBar ......
我有什么:
我想做什么:
问题是,例如,我想将日期定位在标题的底部......
以下是标题的简化代码:
<?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>
这是页脚:
<?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>
,这是完整界面的简化代码:
<?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>
有什么想法吗?
先谢谢,
的Valentin
答案 0 :(得分:0)
当权重在同一布局文件中时,我发现更容易阅读,如下所示:
<?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>
在页眉和页脚中,我删除了layout_weight,并将height / width设置为match_parent。主要布局将覆盖这些。
更新:添加了标题+页脚。
部首:
<?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>
页脚:
<?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>