android – 仅隐藏Scroll上的Action栏而不是操作栏选项卡

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

对于Eg:

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

我正在展示我到目前为止得到的输出.

向下滚动后:

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

向上滚动后:

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

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>

我的问题是,向下滚动它只需要隐藏操作栏而不是操作栏选项卡.

解决方法

我认为 this library及其样本可以帮到你.

看看右上角的gif动画:

我认为示例文件名为“ViewPagerTabScrollViewActivity

相关文章

###实现效果*本实例主要实现用ViewPage和Fragment实现选项卡...
一、安装 JDK 下载JDK最新版本,下载地址如下: http://www....
这篇“android轻量级无侵入式管理数据库自动升级组件怎么实现...
今天小编给大家分享一下Android实现自定义圆形进度条的常用方...
这篇文章主要讲解了“Android如何解决字符对齐问题”,文中的...
这篇文章主要介绍“Android岛屿数量算法怎么使用”的相关知识...