java - android:layout_weight 考虑 FrameLayout 中嵌入 ImageViewer 的大小

标签 java android android-layout

所以我的 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/

相关文章:

java - 编译器如何推断 Java 泛型中的类型

java - 如何将参数注入(inject) JUnit 5 扩展

java - Android AudioRecord 不会初始化

android - 为什么我的 Material 设计组件没有注册适当的颜色,如 material.io 网站上所述?

android - 约束布局 : change constraints programmatically

android - 解析android资源@android :color/transparent#00000000

Java 检查 Linux 上的互联网连接问题

使用svn覆盖路径文件导入的java项目

android - ScrollView 内的多个可滚动 TextView

android - 自动点击提交按钮以及如何通过提交按钮的时间限制?