简体   繁体   English

从 View.GONE 状态到 View.VISIBLE 的 setVisibility 无法正常工作

[英]setVisibility from View.GONE state to View.VISIBLE not working properly

I have a real strange problem and I don't know how to solve it.我有一个真正奇怪的问题,我不知道如何解决它。 I have a View inside a LinearLayout with attribute android:visibility="gone" this is the layout file我在 LinearLayout 中有一个 View 属性为 android:visibility="gone" 这是布局文件

<?xml version="1.0" encoding="utf-8"?>
<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="wrap_content"
    android:background="@color/bg"
    android:orientation="vertical">

    <TextView
        android:id="@+id/titleTextView"
        android:gravity="end"
        android:text="dfgdfg"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:background="@android:color/transparent"
        android:paddingTop="5dp"
        android:paddingBottom="5dp"/>

    <View
        android:layout_width="match_parent"
        android:layout_height="8dp"
        android:background="@drawable/shadow"
        android:id="@+id/preLollipopShadow"
        android:visibility="gone"/>

</LinearLayout>

when I want to change visibility of view with preLollipopShadow I use this code当我想使用 preLollipopShadow 更改视图的可见性时,我使用此代码

if (newPosition == StickyHeaderLayoutManager.HeaderPosition.STICKY) {
                        ((ViewGroup)header).getChildAt(1).setVisibility(View.VISIBLE);

                    }
                    else
                    {
                        ((ViewGroup)header).getChildAt(1).setVisibility(View.GONE);

                    }

it is not working as I expect , I want that shadow be visible on sticky mode and be gone otherwise .它不像我期望的那样工作,我希望在粘性模式下可以看到阴影,否则就消失了。

how can I achieve that ?我怎样才能做到这一点?

UPDATE 1 : When I start with visibility "invisible" and switch to "visible" and back it is working but not with starting state of "gone" on my preLollipopShadow view.更新 1 :当我以“不可见”的可见性开始并切换到“可见”并返回时,它正在工作,但在我的 preLollipopShadow 视图上没有“消失”的起始状态。

UPDATE 2 : The view is inside a RecyclerView , Does not updating view visibility somehow related to being nested into a RecyclerView ?更新 2:视图位于 RecyclerView 内,是否不更新与嵌套到 RecyclerView 中有关的视图可见性?

The View you want to hide and show has an id of preLollipopShadow attached to it.您要隐藏和显示的视图附加了一个 preLollipopShadow id Its easy to find the view by its id.很容易通过它的 id 找到视图。

parentView.findViewById(R.id.preLollipopShadow);

or或者

findViewById(R.id.preLollipopShadow);

if you want to reference the view from an activity.如果您想从活动中引用视图。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 在view.setVisibility(View.GONE)和view.setVisibility(View.VISIBLE)之后刷新RelativeLayout - RelativeLayout refresh after view.setVisibility(View.GONE) and view.setVisibility(View.VISIBLE) 如何从 View.gone 恢复视图。 在 xml 中使用 'android:visibility="gone"' 后 setVisibility(View.VISIBLE) 不工作 - How to recover view from View.gone. setVisibility(View.VISIBLE) not working after using 'android:visibility="gone"' in xml setVisibility(View.GONE) 不起作用? 为什么? - setVisibility(View.GONE) is not working! Why? Android setVisibility(View.Visible)不适用于布局 - Android setVisibility(View.Visible) not working on a layout fab.setVisibility(View.GONE)无法正常工作 - fab.setVisibility(View.GONE) isn't working 使用以setVisibility(View.GONE)开头的布局中的值进行发布; - Issue using values from layout that starts with setVisibility(View.GONE); setVisibility(View.GONE) 缩小显示尺寸 - setVisibility(View.GONE) shrinking display size setVisibility(View.GONE)在Fragment中不起作用 - setVisibility(View.GONE) does not work in Fragment Android setVisibility View.INVISIBLE和View.GONE无法正常工作 - Android setVisibility View.INVISIBLE and View.GONE aren't working Android System.Err是否支持setVisibility(View.GONE)? - Android System.Err for setVisibility(View.GONE)?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM