我在向下滚动时尝试隐藏操作栏时遇到问题。然后在向上滚动时,必须再次显示操作栏。
For Eg:
我提到了这个Tutorial http://www.techrepublic.com/article/pro-tip-maximize-android-screen-real-estate-by-showing-and-hiding-the-action-bar/在这里您可以看到输出以及与隐藏和显示操作栏相关的相应代码。
我正在展示output到目前为止我得到了什么。
向下滚动后:
上面显示的屏幕截图,它也隐藏了操作栏选项卡。但它必须仅隐藏操作栏。这是主要问题。
向上滚动后:
上面的屏幕截图显示它显示了带有选项卡的操作栏。
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_erated.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>
我的问题是,向下滚动时,它只需要隐藏操作栏而不是操作栏选项卡。
I think 这个图书馆 https://github.com/ksoichiro/Android-ObservableScrollView它的样本可以帮助你。
看右上角的gif动画:
我认为示例文件名为“ViewPagerTabScrollViewActivity https://github.com/ksoichiro/Android-ObservableScrollView/blob/master/observablescrollview-samples/src/main/java/com/github/ksoichiro/android/observablescrollview/samples/ViewPagerTabScrollViewActivity.java"
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)