Reputation: 373
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
<?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
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.
UPDATE 2 : The view is inside a RecyclerView , Does not updating view visibility somehow related to being nested into a RecyclerView ?
Upvotes: 1
Views: 2610
Reputation: 682
The View you want to hide and show has an id of preLollipopShadow attached to it. Its easy to find the view by its id.
parentView.findViewById(R.id.preLollipopShadow);
or
findViewById(R.id.preLollipopShadow);
if you want to reference the view from an activity.
Upvotes: 1