当我在滚动down.Then时试图隐藏动作栏时,我遇到了一个问题,动作栏必须再次显示。
For Eg:
我引用了这个教程.Here,您可以看到与隐藏和显示操作栏相关的输出和相应的代码。
我正在向输出展示到现在为止我得到了什么。
向下滚动后的:
上面显示的屏幕截图,它隐藏了动作栏选项卡also.But,它只需要隐藏操作条,这就是主要问题。
滚动后的:
上面的屏幕截图显示了带有选项卡的动作条的背面。
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>
我的问题是,当它向下滚动时,它只需要隐藏动作栏,而不是动作栏选项卡。
发布于 2014-12-02 23:34:39
https://stackoverflow.com/questions/27163374
复制