0

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

我试图在下面隐藏一个视图MapView。一旦我将其可见性设置为GONE,就会MapView闪烁。由于我必须动态添加更多标记,因此无法保留MapViewand bottomViewin 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,但没有运气。它显示出比以前更多的灰色空间。

        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);
4

1 回答 1

1

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

android:layout_above="@+id/options_layout"

......也许让高度match_parent。然后,lay_fr_map_inc将保持全高,但底部将options_layout在它出现时被隐藏(而不是向上滑动)。

执行此操作时不要忘记更改地图填充,以免遮挡 Google 徽标(这是违反规则的):setPadding()

于 2018-11-02T22:32:13.013 回答