仅隐藏“滚动”操作栏选项卡上的“操作”栏

时间:2014-11-27 05:00:27

标签: android android-actionbar

我在向下滚动时尝试隐藏操作栏时出现问题。然后在向上滚动时,操作栏必须再次显示。

对于Eg:

我引用了这个Tutorial。在这里你可以看到与隐藏相关的输出和相应代码并显示操作栏。

我正在展示输出到目前为止我得到的东西。

enter image description here

向下滚动:

enter image description here

上面显示的屏幕截图,它也隐藏了操作栏标签。但是它必须只隐藏操作栏。这是主要问题。

向上滚动后

enter image description here

上面的屏幕截图显示它会显示带有标签的操作栏。

TopRatedFragment.java:

import info.androidhive.tabsswipe.R;
import android.app.ActionBar;
import android.content.res.TypedArray;
import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.view.ViewTreeObserver;
import android.view.Window;
import android.widget.ScrollView;

public class TopRatedFragment extends Fragment implements ViewTreeObserver.OnScrollChangedListener {

    private float mActionBarHeight;
    private ActionBar actionBar;


    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container,
            Bundle savedInstanceState) {

        View rootView = inflater.inflate(R.layout.fragment_top_rated, container, false);

        final TypedArray styledAttributes = getActivity().getTheme().obtainStyledAttributes(
                new int[] { android.R.attr.actionBarSize });
        mActionBarHeight = styledAttributes.getDimension(0, 0);
        styledAttributes.recycle(); 
        actionBar = getActivity().getActionBar();  



        ((ScrollView)rootView.findViewById(R.id.parent)).getViewTreeObserver().addOnScrollChangedListener(this);


        return rootView;
    }


    @Override
    public void onScrollChanged() {

        float y = ((ScrollView)getActivity().findViewById(R.id.parent)).getScrollY();
        if (y >= mActionBarHeight && actionBar.isShowing()) {
            actionBar.hide();
        } else if ( y==0 && !actionBar.isShowing()) {
            actionBar.show();
        }
    }
}

fragment_top_rated.xml:

<?xml version="1.0" encoding="utf-8"?>
    <ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
        android:id="@+id/parent"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent" >

        <LinearLayout
            android:id="@+id/linearLayout1"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
              android:paddingTop="?android:attr/actionBarSize" 
            android:orientation="vertical" >  

            <Button
                android:id="@+id/button1"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:text="Button" />

            <Button
                android:id="@+id/button5"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:text="Button" />

               .
               .
    </LinearLayout>

    </ScrollView>

我的问题是,向下滚动时只需要隐藏操作栏而不是操作栏标签。

1 个答案:

答案 0 :(得分:16)

我认为this library及其示例可以为您提供帮助。

看看右上角的gif动画:

image.gif

我认为示例文件名为&#34; ViewPagerTabScrollViewActivity&#34;

相关问题