[英]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.