我越来越疯狂的Android视图。我想要一个带顶部(A)的酒吧和一个酒吧的底部(C)与我的应用程序height="wrap_content"
的布局。中间的完整剩余空间(B)应该是带有另一个布局或TextView
或其他内容的内容区域。但我无法得到这个工作。我尝试了很多布局,但是当我对B执行android:layout_height="match_parent"
时,C消失了。有任何想法吗?由于事先布局与顶部酒吧,底部酒吧和剩余空间内容视图
3
A
回答
6
可以使用Android:layout_weight属性来实现这一点,但你的父容器必须是一个的LinearLayout,在我的例子中,我只使用的LinearLayout作为父视图的孩子,但你可以使用另一种类型的观:
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/container"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight="1"
android:orientation="vertical">
<LinearLayout
android:id="@+id/layout_a"
android:layout_width="match_parent"
android:layout_height="wrap_content">
</LinearLayout>
<LinearLayout
android:id="@+id/layout_b"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1">
</LinearLayout>
<LinearLayout
android:id="@+id/layout_c"
android:layout_width="match_parent"
android:layout_height="wrap_content">
</LinearLayout>
</LinearLayout>
如果你是好奇,想知道它是如何工作......这里是explanation,好运:)
0
把内容转换成一个RelativeLayout
与alignParentTop
和alignParentBottom
属性为内容甲和Ç并且还below
和above
相关属性内容乙,如下所示:
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent" >
<!-- create content A and C before -->
<LinearLayout
android:id="@+id/A"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:orientation="vertical" > </LinearLayout>
<LinearLayout
android:id="@+id/C"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:orientation="vertical" > </LinearLayout>
<!-- create content B regarding the previous ids -->
<LinearLayout
android:id="@+id/B"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_below="@id/A"
android:layout_above="@id/C"
android:orientation="vertical" > </LinearLayout>
</RelativeLayout>
您可以尝试更改B的高度与wrap_content
而不是match_parent
如果这不起作用。让我知道这是否有帮助。
+1
是的,这将工作,只是用相同的规格嘲笑了一个视图,它工作得很好。使用重量的 – OceanLife
0
使用重量:
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent">
<FrameLayout
android:id="@+id/A"
android:layout_width="match_parent"
android:layout_height="50dp">
<!-- Your view here or replace FrameLayout -->
</FrameLayout>
<FrameLayout
android:id="@+id/B"
android:layout_width="match_parent"
android:layout_height="0px"
android:layout_weight="1">
<!-- Your view here or replace FrameLayout -->
</FrameLayout>
<FrameLayout
android:id="@+id/C"
android:layout_width="match_parent"
android:layout_height="50dp">
<!-- Your view here or replace FrameLayout -->
</FrameLayout>
</LinearLayout>
将高度设置为0有利于性能,因为重量无论如何都会改变它。
0
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
<TextView
android:id="@+id/top_bar"
android:layout_weight="1"
android:layout_width="match_parent"
android:layout_height="0dp"/>
<TextView
android:id="@+id/middle_area"
android:layout_weight="14"
android:layout_width="match_parent"
android:layout_height="0dp"/>
<TextView
android:id="@+id/bottom_bar"
android:layout_weight="1"
android:layout_width="match_parent"
android:layout_height="0dp"/>
android_layout_weight与LinearLayout中结合能为你做的伎俩。尝试上面的代码,并根据您的需要调整android_layout_weight。 在我的例子中,顶栏将占据屏幕的1/16,底栏将占屏幕的1/16,中间区域占屏幕的14/16。您可以将数字更改为您的自定义需求。
相关问题
- 1. 布局 - 如何填补顶部酒吧和底部酒吧之间的差距
- 2. 酒吧顶部酒吧关闭按钮
- 3. barplot与酒吧从顶部
- 4. WordPress的顶部酒吧和我的顶级酒吧和IE9
- 5. 酒吧内的标签和顶部
- 6. STDIN酒吧在底部
- 7. android webview顶部酒吧
- 8. 透明顶部酒吧ios7
- 9. MPAndroidChart内部酒吧标签
- 10. 试图居中顶部DIV酒吧
- 11. Android工作室:顶部酒吧图标上的空白空间
- 12. Android和顶部酒吧通知
- 13. 顶部和底部酒吧在iPhone模拟器中不可见
- 14. Sencha静态顶部和底部酒吧换页
- 15. 图表布局和酒吧标签
- 16. 更新android酒吧酒吧
- 17. 静电FOO = “酒吧” 与MyClass.foo = “酒吧”
- 18. Android创建底部酒吧菜单
- 19. 底部酒吧顶部的浮动动作按钮
- 20. Highcharts.js结合酒吧/折线图与时间酒吧
- 21. 如何让一个固定在视口底部的酒吧成为页脚底部的酒吧
- 22. 边框伸出顶部酒吧
- 23. HTML顶部酒吧背景拉伸
- 24. Zurb Foundation禁用顶部酒吧折叠
- 25. 在酒吧顶部显示数值
- 26. TinyMCE酒吧总是在顶部
- 27. 固定搜索按钮顶部酒吧
- 28. 我的MacVim顶部的奇怪酒吧?
- 29. 顶部酒吧断点 - 基金会5
- 30. GGPLOT2:改变酒吧的顺序,使数值越小酒吧都在酒吧顶部具有较大值
解决了这个问题。简单的答案,它的作品。 thx所有答案 –
工作正常,在主线性布局更改后android:layout_height =“wrap_content”android:layout_height =“match_parent” – Duque
已修复! :)谢谢@Duque –