布局时闪烁 visible/gone

Flickers while layout visible/gone

有什么方法可以隐藏视图而不闪烁其上面的视图吗?

我正试图在 MapView 下隐藏一个视图。一旦我将其可见性设置为 GONEMapView 就会闪烁。由于我必须动态添加更多标记,无法将 MapViewbottomView 保留在 FrameLayout 中,因为 bottomView 会在小尺寸屏幕中隐藏这些标记。

布局:

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout 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:animateLayoutChanges="true">


    <com.myapp.widgets.MapPlacePicker
        android:id="@+id/lay_fr_map_inc"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_above="@+id/options_layout" />

    <LinearLayout
        android:id="@+id/options_layout"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_alignParentBottom="true"
        android:animateLayoutChanges="true"
        android:background="#FFFFFF"
        android:orientation="vertical"
        android:visibility="visible">

        <com.myapp.widgets.FontTextView
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:gravity="center"
            android:padding="10dp"
            android:text="Please select a location!!"
            android:textAppearance="@android:style/TextAppearance.Small" />

        <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:orientation="horizontal">

            <com.aigestudio.wheelpicker.WheelPicker
                android:id="@+id/main_option_view"
                android:layout_width="0dp"
                android:layout_height="wrap_content"
                android:layout_margin="10dp"
                android:layout_weight="0.5"
                app:wheel_atmospheric="true"
                app:wheel_curved="false"
                app:wheel_item_space="15dp"
                app:wheel_item_text_color="#ffafafaf"
                app:wheel_item_text_size="12dp"
                app:wheel_selected_item_text_color="@color/colorPrimary"
                app:wheel_visible_item_count="3" />

        </LinearLayout>
    </LinearLayout>

</RelativeLayout>

输出:

我也试过TranslationAnimation,但没有成功。它显示出比以前更多的灰色 space。

        int fromY = (visibility == View.GONE) ? 0 : optionLayout.getHeight();
        int toY = (visibility == View.GONE) ? optionLayout.getHeight() : 0;
        if (visibility == View.VISIBLE) {
            optionLayout.setVisibility(visibility);
        }
        TranslateAnimation animate = new TranslateAnimation(
                0,                 // fromXDelta
                0,                 // toXDelta
                fromY,                 // fromYDelta
                toY); // toYDelta
        animate.setDuration(1000);
        animate.setInterpolator(new AccelerateDecelerateInterpolator());
        //animate.setFillAfter(false);
        animate.setAnimationListener(new Animation.AnimationListener() {
            @Override
            public void onAnimationStart(Animation animation) {

            }

            @Override
            public void onAnimationEnd(Animation animation) {
                if (visibility == View.GONE)
                    optionLayout.setVisibility(visibility);
                optionLayout.clearAnimation();
            }

            @Override
            public void onAnimationRepeat(Animation animation) {

            }
        });
        optionLayout.startAnimation(animate);

我在那个动画中没有看到任何闪烁;如果你想避免 lay_fr_map_inc 的垂直调整大小行为,那么你可以删除这个属性:

android:layout_above="@+id/options_layout"

...并可能使高度 match_parent。然后,lay_fr_map_inc 将保持全高,但底部会在出现时被 options_layout 隐藏(而不是向上移动)。

执行此操作时不要忘记更改地图填充,这样就不会遮挡 Google 徽标(这违反了 rules): setPadding()