ActionBar隐藏/显示在RecyclerView中时闪烁

时间:2015-01-05 15:16:15

标签: android xml android-actionbar android-recyclerview

所以在我的情况下,我使用RecyclerView来显示项目列表但是当我在滚动时尝试隐藏操作栏时,我得到了令人烦恼的屏幕闪烁。我在网上搜索了我的问题的答案,但到目前为止还没有运气。那么有谁能告诉我我做错了什么?

这是我的java隐藏操作栏:

     @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;
}

这是recyclerview的XML:

<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"/>

以及操作栏的样式:

<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>

因此,您可以看到我已启用操作栏进行叠加。我也尝试在我称之为recyclerview类的活动中调用操作栏的叠加层,但问题仍然存在...没有运气,闪烁仍然存在,即使我向recyclervie XML添加填充,我只得到一个黑色矩形与动作栏的大小。

以下是我显示recyclelerview的活动的xml:

<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">

ž

        <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 -->

0 个答案:

没有答案