【问题标题】:Hide only the Action bar on Scroll not action bar tabs仅隐藏滚动而不是操作栏选项卡上的操作栏
【发布时间】:2015-01-25 14:53:35
【问题描述】:

我在尝试在向下滚动时隐藏操作栏时遇到问题。然后在向上滚动时,操作栏必须再次显示。

例如:

我提到了这个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>

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

【问题讨论】:

  • 也许这会有所帮助:github.com/ksoichiro/Android-ObservableScrollView ?看看 gif 动画的右上角...
  • 好的,已发布。希望对您有所帮助。
  • 操作栏标签已弃用。您需要首先将操作栏选项卡迁移到 viewpager。

标签: android android-actionbar


【解决方案1】:

我认为this library 及其示例可以帮助您。

看右上角的gif动画:

我认为示例文件名为“ViewPagerTabScrollViewActivity

【讨论】:

  • 那不行。因为即使在单个活动中也没有布局。
  • 什么输出?我不明白。
  • 我和那个 Github 发布者谈过了。我得到了这样的回复。The sample app cannot be built without layout files. I tried importing the project again, but unfortunately I couldn't see those errors... So... I have some questions. 1. What is your OS? (I'm using Mac OS X 10.10) 2. What commit are you trying to build? (Git commit hash, like "36cd555" or something) 3. What is your Android Studio version? (I'm using or tested on 1.0 RC 1, RC 2 and RC 4.)
  • 4. Does the command line build also fail? ("./gradlew assembleDebug" on Mac/Linux and "gradlew.bat assembleDebug" on Windows. If the build succeeded, you can get the apk in "observablescrollview-samples/build/outputs/apk/" directory.) 5. Does it happen only on this project? 6. Are the Android SDK location and JDK location properly set on Default Project Structure setting? (File &gt; Other Settings &gt; Default Project Structure) 谢谢鹿岛宗一郎`
  • @Naruto 对不起,我还是不明白。你有没有推出他的样品?这些问题是给我的吗?如果是这样,这是我的答案: 1. 我使用 Windows OS 8.1 。 2. 用的是普通的,没什么特别的。 3. 我在 Android Studio 和 Eclipse 上都试过,没有检查版本,但我总是尽量保持更新。 4. 我从未尝试在命令行上使用 Gradle。我对 Gradle 很陌生。 5. 会发生什么? 6. 是的,它对我来说很好。
猜你喜欢
  • 1970-01-01
  • 2016-08-04
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多