父视图clipChildren奇怪的行为(不在某一点工作)

时间:2015-07-24 17:27:17

标签: android android-layout

问候堆栈社区。

我正在创建这篇文章,因为我遇到了一个我似乎无法解决的问题,甚至没有正确弄清楚为什么会这样。我已经成为Android开发者近三年了,所以我想我知道自己的方式,但在这种情况下,我有一个阻塞问题。

我遇到的问题与viewGroups和子视图有关,其中子视图的宽度大于父视图的宽度。我已经尝试将clipChildren = falseclipToPadding = false设置为层次结构中的所有父视图,但它们一直工作到特定点,直到第一代根父视图组。我已经制作了我的问题的简化版本,以便您也可以亲自了解我的问题和具体问题。下面是准备复制粘贴的测试布局,以便您可以模拟我的问题:

<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="400dp"
android:layout_height="match_parent"
android:background="#55ff0000"
android:orientation="vertical">


<FrameLayout
    android:layout_width="230dp"
    android:layout_height="80dp"
    android:background="#ffacde"
    android:clipChildren="false">

    <FrameLayout
        android:layout_width="180dp"
        android:layout_height="60dp"
        android:background="@color/accent_material_light"
        android:clipChildren="false"
        android:orientation="horizontal">

        <!--
        <FrameLayout android:layout_width="60dp" android:layout_height="60dp" android:background="@color/accent_material_dark">
        </FrameLayout>
        //-->


        <FrameLayout
            android:id="@+id/sdfIasdftem"
            android:layout_width="140dp"
            android:layout_height="60dp"
            android:background="#4f0f5f00"
            android:clipChildren="false">


            <FrameLayout
                android:id="@+id/sdfItem"
                android:layout_width="120dp"
                android:layout_height="60dp"
                android:background="#ffffff00"
                android:clipChildren="false">

                <FrameLayout
                    android:id="@+id/middleItem"
                    android:layout_width="60dp"
                    android:layout_height="60dp"
                    android:background="#ff0000ff"
                    android:clipChildren="false">

                    <TextView
                        android:layout_width="300dp"
                        android:layout_height="30dp"
                        android:background="#00ff00"
                        android:gravity="center"
                        android:text="Hello" />

                </FrameLayout>

            </FrameLayout>

        </FrameLayout>

        <!--
          <FrameLayout android:layout_width="60dp" android:layout_height="60dp" android:background="#99550066">

          </FrameLayout>
        -->

    </FrameLayout>

</FrameLayout>

现在,我要展示的孩子在

之前保持不受限制

<FrameLayout android:layout_width="230dp"

任何人都可以解释为什么会发生这种情况,也许可以解决这个问题?对我来说,它看起来很奇怪。如果您将clipChildren = false添加到根FrameLayout而不是它的工作,但它不应该依赖于此,所以问题仍然存在。

感谢您花时间阅读本文并帮助我解决这个复杂的难题。

最好的问候。

鲁宾

0 个答案:

没有答案