【问题标题】:How to handle nested FrameLayout properly如何正确处理嵌套的 FrameLayout
【发布时间】:2013-07-19 07:29:59
【问题描述】:

我正在使用 FrameLayouts 将图像重叠在图像上,但我无法理解在这种特殊情况下,我的内部 FrameLayout 没有显示在另一个图像的前面。这是理论:

这是实际情况:

这是我的 XML:

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/mypage_container"
android:layout_width="match_parent"
android:layout_height="match_parent" >

<FrameLayout
    android:id="@+id/frame"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content" >

    <RelativeLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content" >

        <ImageView
            android:id="@+id/cover_photo"
            android:layout_width="match_parent"
            android:layout_height="180dp"
            android:layout_marginTop="120dp"
            android:scaleType="fitXY"
            android:src="#CCFF0000" />

        <FrameLayout
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_below="@id/cover_photo" >

            <ImageView
                android:layout_width="105dp"
                android:layout_height="90dp"
                android:layout_below="@id/cover_photo"
                android:adjustViewBounds="true"
                android:src="@color/aqua"
                android:translationY="-45dp" />

            <ImageView
                android:layout_width="80dp"
                android:layout_height="80dp"
                android:layout_marginLeft="15dp"
                android:src="@color/green"
                android:translationY="-40dp" />
        </FrameLayout>

    </RelativeLayout>
</FrameLayout>

我是不是把内部的 FrameLayout 放错了?我不知道该怎么办了。 任何帮助将不胜感激。谢谢!

【问题讨论】:

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


    【解决方案1】:

    这是因为你的 FrameLayout 有这行:android:layout_below="@id/cover_photo"。你可以像这样拥有 FrameLayout:

    <FrameLayout
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_marginBottom="-40dp"
            android:layout_alignBottom="@id/cover_photo" >
    

    【讨论】:

    • 我忘了省略那一行,但那一行基本上对布局没有影响,因为它的父级是 FrameLayout。我删除了那条线,没有任何改变。不过感谢您的回答!
    • 抱歉,我更新了我的答案,希望对您有所帮助。顺便说一句,为什么你有相对 -> 框架 -> 相对?为什么你没有RelativeLayout?
    • 好的,我得到了你的解决方法。不是视图下方的视图并将其向上移动,而是将其在底部对齐并向下移动。杰出的!顺便说一句,我在父RelativeLayout 下还有其他东西,更多ImageView 和另一个RelativeLayout。这只是我整体布局的一个片段。非常感谢!
    • 很高兴能帮上忙。
    猜你喜欢
    • 1970-01-01
    • 2023-04-08
    • 1970-01-01
    • 2021-03-16
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-05-15
    • 2019-08-26
    相关资源
    最近更新 更多