【问题标题】:Android: RelativeLayout inside FrameLayout, width height bugAndroid:FrameLayout内的RelativeLayout,宽度高度错误
【发布时间】:2013-12-03 11:06:59
【问题描述】:

我有什么:

activity_comics.xml - 两个片段的布局容器:漫画列表 (view_comicses.xml) 和详细漫画视图

<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:gravity="center_vertical"
    android:id="@+id/comics_fragment_container">
</FrameLayout>

view_comicses.xml - 带有交错列表视图的片段

<com.agimind.widget.huewu.pla.lib.MultiColumnListView
    xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:pla="http://schemas.android.com/apk/res-auto"
    android:id="@+id/multicollist"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    pla:plaColumnNumber="2"
    pla:plaLandscapeColumnNumber="3">
</com.agimind.widget.huewu.pla.lib.MultiColumnListView>

view_comics_detail.xml - 漫画详细视图片段

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:background="@android:color/black">

    <ImageView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:id="@+id/comics_image"
        android:layout_centerInParent="true" />

</RelativeLayout>

view_comicses.xmlview_comics_detail.xml 片段添加到activity_comics.xml 之后,生成的布局应该是这样的:

<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:gravity="center_vertical"
android:id="@+id/comics_fragment_container">

    <com.agimind.widget.huewu.pla.lib.MultiColumnListView
        xmlns:android="http://schemas.android.com/apk/res/android"
        xmlns:pla="http://schemas.android.com/apk/res-auto"
        android:id="@+id/multicollist"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        pla:plaColumnNumber="2"
        pla:plaLandscapeColumnNumber="3">
    </com.agimind.widget.huewu.pla.lib.MultiColumnListView>

    <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:background="@android:color/black">

        <ImageView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:id="@+id/comics_image"
            android:layout_centerInParent="true" />

    </RelativeLayout>

</FrameLayout>

但由于某些原因,结果布局看起来像这样

RelativeLayout 的宽度和高度等于 match_parent,但在渲染时好像等于 wrap_content。为什么会这样?我尝试了 FrameLayoutRelativeLayout 的不同参数,但不起作用,任何帮助将不胜感激!

【问题讨论】:

    标签: android android-layout android-fragments android-relativelayout android-framelayout


    【解决方案1】:

    RelativeLayout 正在尝试匹配 FrameLayout 的宽度,但由于 MultiColumnListView 存在而无法匹配。然后 FrameLayout 将其可用空间拆分给两个孩子。

    如果您希望 RelativeLayout 和 MultiColumnListView 都具有与 FrameLayout 相同的宽度(并且重叠),您需要将 FrameLayout 更改为 RelativeLayout。

    FrameLayout 更常用于显示单个子项。可以添加多个孩子,但您需要为每个孩子指定 android:layout_gravity 以控制他们的位置。

    【讨论】:

      【解决方案2】:

      尝试更改 RelativeLayout 的背景颜色。你能在你的图像后面看到它吗?您的 RelativeLayout 匹配父级,但您的 ImageView 包装内容。您的图片大小是否适合填满屏幕?

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2013-10-26
        • 1970-01-01
        • 2017-10-14
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多