1

我有一个FrameLayout我想在底部的设备窗口之外,所以用户看不到它。当用户按下某个东西时,这FrameLayout是一部分的整个片段将向上移动,这应该暴露FrameLayout,因为它现在在视图中。为此,我在其所有父级上设置了一个负边距FrameLayout并将clipChildrenclipToPadding设置为 false。但是,这似乎不起作用。

我试图手动添加属性

    android:clipChildren="false"
    android:clipToPadding="false"

对每一个可能的父视图,没有任何运气。可以肯定的是,我什至使用这种方法循环父母并以编程方式设置这些属性:

public void disableClipOnParents(View v) {
    if (v.getParent() == null) {
        return;
    }

    if (v instanceof ViewGroup) {
        ((ViewGroup) v).setClipChildren(false);
    }

    if (v.getParent() instanceof View) {
        disableClipOnParents((View) v.getParent());
    }
}

当我向上滑动持有片段时,这个视图被剪裁的原因可能是什么?这是片段的布局 XML:

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@color/colorPrimary"
android:orientation="vertical"
android:clipChildren="false"
android:clipToPadding="false">

<android.support.constraint.ConstraintLayout
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:background="@color/colorPrimary">

    <FrameLayout
        android:layout_width="match_parent"
        android:layout_height="0dp"
        android:layout_marginTop="40dp"
        app:layout_constraintBottom_toTopOf="parent"
        app:layout_constraintDimensionRatio="H, 1:1"
        app:layout_constraintLeft_toLeftOf="parent"
        app:layout_constraintRight_toRightOf="parent"
        app:layout_constraintTop_toTopOf="parent" />
</android.support.constraint.ConstraintLayout>

<RelativeLayout
    android:adjustViewBounds="true"
    android:id="@+id/rlPlaceholder"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:background="@color/colorPrimary"
    android:clipChildren="false"
    android:clipToPadding="false">

    <ImageView
        android:id="@+id/ivCaptureImage"
        android:layout_width="75dp"
        android:layout_height="75dp"
        android:layout_centerInParent="true"
        android:src="@drawable/camera_shutter_selector" />
    <FrameLayout
        android:id="@+id/flStart"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:background="@color/colorPrimaryLight"
        android:layout_alignParentBottom="true"
        android:layout_marginBottom="-40dp">
        <TextView
            android:layout_width="wrap_content"
            android:layout_height="60dp"
            android:gravity="center_vertical"
            android:layout_gravity="center_horizontal"
            android:textSize="18dp"
            android:fontFamily="sans-serif"
            android:textColor="@color/white"
            android:text="START"/>
    </FrameLayout>
</RelativeLayout>

</LinearLayout>

id 为flStartFrameLayout底部是应该位于屏幕外部然后在单击事件上滑入的视图(片段的顶部滑出)。

非常感谢任何帮助

4

2 回答 2

1

Android 官方不支持负边距。他们从来不应该工作,但由于某些布局中的错误,他们做到了。谷歌认为它足够有用,他们从未修复过这个错误,但他们也表示这不一定是他们一直支持的东西。

完成这项工作的正确方法是将该视图的高度设置为 0,然后当您希望它在视图中显示动画时,通过增加其高度直到它达到您想要的完整尺寸。

于 2018-07-14T03:38:23.567 回答
0

当顶级容器是 a ConstraintLayout(而不是LinearLayout你现在拥有的)时,我已经做了这种事情。在这种情况下,您可以将隐藏的 FrameLayout 设置为具有 的约束top_ToBottomOf="parent",这会将其定位在屏幕底部的底部,然后将其向上动画以显示它,如下所示

myFrameLayout.animate().translationY(-myFrameLayout.getHeight()).setInterpolator(
        new DecelerateInterpolator()).setListener(new AnimatorListenerAdapter() {
            @Override
            public void onAnimationEnd(Animator animation) {
                super.onAnimationEnd(animation);
                // do anything you need to do once the animation is done
            }
}).setDuration(1000);
于 2018-07-14T03:04:30.477 回答