So in my case I am using a RecyclerView to display a list of items but when I try to hide the action bar while scrolling I get this annoying flickering of the screen. I have searched the web for an answer to my problem but so far there has been no luck. So can anyone tell me what I am doing wrong?
here is my java for hiding the action bar:
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
this.container = container;
this.inflater = inflater;
timePassed = System.currentTimeMillis();
if(hasMoreResults) {
rootView = inflater.inflate(R.layout.home_zone, container, false);
rootView.findViewById(R.id.imgAdsMap).setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
startActivity(new Intent(context, AdsMap.class));
}
});
recyclerViewZone = (RecyclerView) rootView.findViewById(R.id.recyclerViewZone);
recyclerViewZone.setVerticalScrollBarEnabled(true);
// 2. set layoutManger
manager = new LinearLayoutManager(context);
recyclerViewZone.setLayoutManager(manager);
recyclerViewZone.setItemAnimator(new DefaultItemAnimator());
recyclerViewZone.setOnScrollListener(new RecyclerView.OnScrollListener()
{
int mLastFirstVisibleItem = 0;
@Override
public void onScrollStateChanged(RecyclerView recyclerView, int newState)
{
super.onScrollStateChanged(recyclerView, newState);
if (newState == RecyclerView.SCROLL_STATE_IDLE && !generatedAdsFromScroll)
{
generatedAdsFromScroll = true;
runSplitRequest(10);
}
}
//Hiding the Action Bar for better view of the listed items
@Override
public void onScrolled(RecyclerView recyclerView, int dx, int dy) {
super.onScrolled(recyclerView, dx, dy);
final int currentFirstVisibleItem = manager.findFirstVisibleItemPosition();
if (currentFirstVisibleItem > this.mLastFirstVisibleItem)
{
ActionBar bar = getActivity().getActionBar();
bar.hide();
myButton = (RadioGroup)getActivity().findViewById(R.id.radioButtonGroup);
myButton.setVisibility(View.GONE);
}
else if (currentFirstVisibleItem < this.mLastFirstVisibleItem)
{
ActionBar bar = getActivity().getActionBar();
bar.show();
myButton = (RadioGroup)getActivity().findViewById(R.id.radioButtonGroup);
myButton.setVisibility(View.VISIBLE);
}
this.mLastFirstVisibleItem = currentFirstVisibleItem;
}
});
runSplitRequest(20);
}
else
rootView = inflater.inflate(R.layout.error_internet_connection, container, false);
return rootView;
}
This is the XML of the recyclerview:
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="fill_parent"
android:layout_height="match_parent" >
<android.support.v7.widget.RecyclerView
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/recyclerViewZone"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingTop="?android:attr/actionBarSize"
android:clipToPadding="false"
android:scrollbarStyle="outsideOverlay"
tools:context=".MainActivity"
android:scrollbars="vertical" />
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/imgAdsMap"
android:src="@drawable/map_button_map_down"
android:layout_marginRight="5dp"
android:layout_marginBottom="5dp"
android:layout_alignParentBottom="true"
android:layout_alignParentRight="true"
android:layout_alignParentEnd="true"/>
and the style of the action bar:
<resources>
<!-- Base application theme. -->
<style name="AppTheme" parent="android:Theme.Holo.Light.DarkActionBar">
<!-- Customize your theme here. -->
<item name="android:windowActionBarOverlay">true</item>
</style>
<dimen name="image_detail_height">200dp</dimen>
So as you can see I have enabled the action bar to overlay. I have also tried with calling the overlay of the action bar in the activity I call the recyclerview class but the problem remains... no luck the flickering is still there and even if I add padding to the recyclervie XML i just get a black rectangle with the size of the action bar.
Here is the xml of the activity I display the recyclerview:
<android.support.v4.widget.DrawerLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/drawer_layout"
android:layout_width="match_parent"
android:layout_height="match_parent" >
<LinearLayout
android:background="@android:color/black"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:weightSum="1" >
<FrameLayout
android:layout_width="match_parent"
android:layout_height="1dp"
android:background="#353535"/>
<RadioGroup
android:id="@+id/radioButtonGroup"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:layout_gravity="center_horizontal">
z
<RadioButton
android:button="@null"
android:checked="true"
android:contentDescription="ZONA"
android:background="@drawable/tab_back_selector"
android:textColor="@color/tab_text_color"
android:textSize="12sp"
android:layout_weight="1"
android:id="@+id/tabZoneHome"
android:padding="14dp"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:text="@string/home_tab_zone"
android:gravity="center"/>
<RadioButton
android:button="@null"
android:contentDescription="VISITADAS"
android:background="@drawable/tab_back_selector"
android:textColor="@color/tab_text_color"
android:textSize="12sp"
android:layout_weight="1"
android:id="@+id/tabVisitedHome"
android:padding="14dp"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:text="@string/home_tab_visited"
android:gravity="center"
android:checked="false" />
<RadioButton
android:button="@null"
android:contentDescription="SUGERENCIAS"
android:background="@drawable/tab_back_selector"
android:textColor="@color/tab_text_color"
android:textSize="12sp"
android:layout_weight="1"
android:id="@+id/tabSuggestionsHome"
android:padding="14dp"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:text="@string/home_tab_suggestions"
android:gravity="center"
android:checked="false" />
</RadioGroup>
<RelativeLayout
android:id="@+id/ad_detailholder"
android:layout_width="match_parent"
android:layout_height="match_parent">
<FrameLayout
android:id="@+id/frame_container"
android:layout_width="match_parent"
android:layout_height="match_parent"/>
<FrameLayout
android:layout_width="match_parent"
android:layout_height="6dp"
android:background="@drawable/quickview_top_gradient"/>
</RelativeLayout>
<!-- Framelayout to display Fragments -->
</LinearLayout>
<!-- Listview to display slider menu -->