所附图像包含3布局
两种线性布局都是相同大小和重叠的。
我只想知道如何在相对布局中安排这两个线性布局,这样线性布局1 &线性布局2将有90%的父级高度。另外,线性布局1必须对齐到相对布局的顶部,而线性布局2必须对相对布局的底部。
任何简单的工作解决方案都将不胜感激。(我是android工作室的新手)

发布于 2016-07-17 14:02:41
来自Android 文档
<android.support.percent.PercentRelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent">
<LinearLayout
android:layout_width="match_parent"
app:layout_heightPercent="90%"
android:layout_alignParentTop="true"/>
<LinearLayout
android:layout_width="match_parent"
app:layout_heightPercent="90%"
android:layout_alignParentBottom="true"/>
</android.support.percent.PercentRelativeLayout>LinearLayouts重叠的顺序对应于定义它们的顺序。
发布于 2016-07-17 13:55:23
很好的问题,您可以使用PercentRelativeLayout而不是RelativeLayout来调整90%的高度,然后使用这个属性
android:layout_alignParentTop = true 为你的第一次LinearLayout和
android:layout_alignParentBottom = true 对于第二个RelativeLayout
它会将你的LinearLayouts贴在你想要的RelativeLayout里面。
有关如何使用PercentRelativeLayout 这里的问题,请参阅以下问题
如果你也想要层叠效果,就像你在图中看到的那样
android:elevation property on your both `LinearLayout`.代码摘自@Svit的另一个答案以进行完整解释
<android.support.percent.PercentRelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent">
<LinearLayout
android:layout_width="match_parent"
app:layout_heightPercent="90%"
android:layout_alignParentTop="true"/>
<LinearLayout
android:layout_width="match_parent"
app:layout_heightPercent="90%"
android:layout_alignParentBottom="true"/>
</android.support.percent.PercentRelativeLayout>发布于 2016-07-17 14:01:24
这里有另一种方法
android:gravity属性(第一个布局顶部和第二个布局底部)。然后你就可以得到所需的结果。
https://stackoverflow.com/questions/38421843
复制相似问题