所以我的 main.xml 看起来像这样:
<?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>
我想要完成的是将屏幕分成三部分:高度相等的页眉和页脚以及剩余部分的正文。
当我运行这段代码时, headerFrameLayout 最终的大小是 footerFrameLayout 的大小+ logoImage 的高度。例如:headerFrameLayout=163、logoImage=58、footerFrameLayout=105 和 bodyLinearLayout=493。
我不明白为什么标题也要考虑照片的大小。有什么想法吗?
最佳答案
这并不明显,但这就是它的工作原理。如果您想要 15%、70%、15% 的分布,请将每个元素的高度设置为 0dp
,而不是 wrap_content
。
关于java - android:layout_weight 考虑 FrameLayout 中嵌入 ImageViewer 的大小,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8192917/