我在向下滚动时试图隐藏操作栏时出现问题.然后在向上滚动时,操作栏必须再次显示.
对于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”