相关疑难解决方法(0)

无法获取clipChildren = false属性

我有一个黄色,RelativeLayout含有较高的红色LinearLayout.

为了使整体LinearLayout可见,我设置android:clipChildren="false",但这不能按预期工作:

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="44dp"
    android:background="#FFFF00"
    android:clipChildren="false" >

    <LinearLayout
        android:layout_width="50dp"
        android:layout_height="100dp"
        android:background="#FF0000"
        android:orientation="vertical" >

    </LinearLayout>

</RelativeLayout>
Run Code Online (Sandbox Code Playgroud)
  • android:clipChildren="true":

在此输入图像描述

红色LinearLayout按预期剪裁

  • android:clipChildren="false":

在此输入图像描述

其中LinearLayout高度被削波,并且在布局中设置的宽度不尊重.

怎么了?

编辑

如果我将容器包装在LinearLayout两个尺寸与其父级匹配的容器中,我得到相同的结果(我检查了LinearLayout容器的容器填满整个屏幕).

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent">

    <RelativeLayout
        android:layout_width="match_parent"
        android:layout_height="44dp"
        android:background="#FFFF00"
        android:clipChildren="false" >

        <LinearLayout
            android:layout_width="50dp"
            android:layout_height="100dp"
            android:background="#FF0000"
            android:orientation="vertical" >
        </LinearLayout>
    </RelativeLayout>

</LinearLayout>
Run Code Online (Sandbox Code Playgroud)

编辑2

如果我将该android:clipChildren="false"属性放在父LinearLayout中,我会得到以下内容:

在此输入图像描述

android view

27
推荐指数
2
解决办法
2万
查看次数

为什么要为片段创建额外的FrameLayout?

在使用层次结构查看器来减少层次结构时,我注意到在每次添加片段时(以"静态"或"动态"方式),片段总是包含在新的FrameLayout中.

这是一个例子:

这是我的活动布局:

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:contentDescription="mainActivityRoot" >

<TextView
    android:id="@+id/hello_world"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:text="@string/hello_world" />

<fragment
    android:name="com.example.testfragments.MainFragment"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:layout_below="@id/hello_world" />

</RelativeLayout>
Run Code Online (Sandbox Code Playgroud)

这是片段布局:

<ProgressBar android:id="@+id/ProgressBar1" xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:contentDescription="mainFragmentRoot"
android:layout_height="match_parent" />
Run Code Online (Sandbox Code Playgroud)

活动源代码除了之外是空的setContentView,而片段源代码只包含

@Override
public View onCreateView(...) {
    return inflater.inflate(R.layout.fragment_main, container, false);
}
Run Code Online (Sandbox Code Playgroud)

现在,

我希望PrograssBar直接在活动根的层次结构中看到,但是有一个额外的FrameLayout,我不知道它来自哪里.这是一个屏幕截图,在黄色中绘制了额外的框架: 转储视图层次结构 - 黄色是坏的

所以,我的问题是 - 它来自哪里?我可以摆脱它吗? 在我的实际应用程序中,这些额外的FrameLayouts正在创建非常深层次的层次结构,这可能对性能有害.

谢谢!

performance android view android-fragments

12
推荐指数
1
解决办法
2388
查看次数

CardView忽略android:clipChildren ="false"

我想要一个包含ImageView的CardView,它与CardView的左边界重叠.我想通过给ImageView一个负余量来做到这一点.通过设置clipChildren ="false",这适用于所有其他布局(LinearLayout/RelativeLayout/FrameLayout).

但是我无法使用CardView.ImageView将被剪裁,并且不会与CardView重叠.

<android.support.v7.widget.CardView
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_marginLeft="15dp"
        android:clipChildren="false">
    <ImageView
           android:layout_marginLeft="-10dp"
           android:background="@drawable/some_picture"
           android:layout_width="50dp"
           android:layout_height="50dp"/>
</android.support.v7.widget.CardView>
Run Code Online (Sandbox Code Playgroud)

android margin android-cardview

9
推荐指数
1
解决办法
3478
查看次数