I\'ve got a view that is effectively is a button. Here is its XML layout (add_new.xml)
You can use :
viewToHide?.postDelayed({ viewToHide?.visibility = View.GONE }, durationInMillis)
For me, it worked if I did the showing/hiding on the next run loop.
parentView.post {
childViewToHide.visibility = View.GONE
}
I had similar issue when using TransitionManager.beginDelayedTransition()
, in the layout inspector I see that the view is Gone
but still taking space, I think it is bug in Android, a workaround is to execute the visibility block with View.post(Runnable action)
set layout_width
and layout_height
to 0
where you want to hide item, by doing this
//if item's parent layout is LinearLayout, change according to your item xml
holder.itemView.setLayoutParams(new LinearLayout.LayoutParams(0,0));
If you want to show itemView
if (ItemBean.isShow())
{
holder.itemView.setVisibility(View.VISIBLE);
holder.itemView.setLayoutParams(new LinearLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT));
} else
{
holder.itemView.setLayoutParams(new LinearLayout.LayoutParams(0, 0));
holder.itemView.setVisibility(View.GONE);
}
header_layout.xml:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent">
<LinearLayout
android:id="@+id/mHeaderView"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<TextView
android:id="@+id/mNoHelpLayout"
android:layout_width="match_parent"
android:layout_height="176dip"
android:background="#ffffffff"
android:gravity="center"
/>
</LinearLayout>
</LinearLayout>
java code:
LayoutInflater mInflater =(LayoutInflater) getActivity().getSystemService(Context.LAYOUT_INFLATER_SERVICE);
View outerView = mInflater.inflate(R.layout.header_layout, null);
mHeaderView = (LinearLayout) outerView.findViewById(R.id.mHeaderView);
use mHeaderView.setVisiable() to control visiable not the outerView.setVisiable(). it works for me.