微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

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

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。

相关推荐