Android 滚动视图滚动在工具栏上停止一次。设置可见性(View.GONE),我必须再次滚动
滚动视图滚动停止在工具栏上。设置可见性(View.GONE)。我必须再次滚动才能继续滚动,但视图没有问题。不可见,但只有AppBar的文本不可见。我还尝试了getSupportActionBar().hide()但下面的结果与我的代码相同Android 滚动视图滚动在工具栏上停止一次。设置可见性(View.GONE),我必须再次滚动,android,android-scrollview,Android,Android Scrollview,滚动视图滚动停止在工具栏上。设置可见性(View.GONE)。我必须再次滚动才能继续滚动,但视图没有问题。不可见,但只有AppBar的文本不可见。我还尝试了getSupportActionBar().hide()但下面的结果与我的代码相同 scrollView.getViewTreeObserver().addOnScrollChangedListener(new ViewTreeObserver.OnScrollChangedListener() { @Override
scrollView.getViewTreeObserver().addOnScrollChangedListener(new ViewTreeObserver.OnScrollChangedListener() {
@Override
public void onScrollChanged() {
int scrollY=scrollView.getScrollY();
if (scrollY>0){
fab.setVisibility(View.INVISIBLE);
if (scrollY>350){
//Here When scrolling reached to 350 scrolling Stops. I have to Scroll Again.
toolbar.setVisibility(View.GONE);
}
Log.d("scrollPosition"," "+scrollY);
}else {
fab.setVisibility(View.VISIBLE);
toolbar.setVisibility(View.VISIBLE);
// I have no problem while scrolling to top.
}
}
});
app_bar_main.xml
<android.support.design.widget.CoordinatorLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context="com.queendevelopers.appalamusicplayer.MainActivity">
<android.support.design.widget.AppBarLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:theme="@style/AppTheme.AppBarOverlay">
<android.support.v7.widget.Toolbar
android:id="@+id/toolbar"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
android:background="?attr/colorPrimary"
app:popupTheme="@style/AppTheme.PopupOverlay" />
</android.support.design.widget.AppBarLayout>
<include layout="@layout/content_main" />
</android.support.design.widget.CoordinatorLayout>
activity_main.xml
<android.support.v4.widget.DrawerLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/drawer_layout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fitsSystemWindows="true"
tools:openDrawer="start">
<include
layout="@layout/app_bar_main"
android:layout_width="match_parent"
android:layout_height="match_parent" />
<android.support.design.widget.NavigationView
android:id="@+id/nav_view"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_gravity="start"
android:fitsSystemWindows="true"
app:menu="@menu/activity_main_drawer" />
</android.support.v4.widget.DrawerLayout>
Styles.xml
<resources>
<!-- Base application theme. -->
<style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar">
<!-- Customize your theme here. -->
<item name="colorPrimary">@color/colorPrimary</item>
<item name="colorPrimaryDark">@color/colorPrimaryDark</item>
<item name="colorAccent">@color/colorAccent</item>
</style>
<style name="AppTheme.NoActionBar">
<item name="windowActionBar">false</item>
<item name="windowNoTitle">true</item>
</style>
<style name="AppTheme.AppBarOverlay" parent="ThemeOverlay.AppCompat.Dark.ActionBar" />
<style name="AppTheme.PopupOverlay" parent="ThemeOverlay.AppCompat.Light" />
</resources>
@颜色/原色
@颜色/原色暗
@颜色/颜色重音
假的
真的
Manifest.xml
android:roundIcon="@mipmap/ic_launcher_round"
android:supportsRtl="true"
android:theme="@style/AppTheme">
<activity
android:name=".MainActivity"
android:label="@string/app_name"
android:theme="@style/AppTheme.NoActionBar">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
android:roundIcon=“@mipmap/ic\u launcher\u round”
android:supportsRtl=“true”
android:theme=“@style/AppTheme”>
我使用的是带有导航抽屉的Android默认模板Android活动我建议在滚动时设置动画,不滚动时设置动画,这将有帮助:@BradleyWilson我尝试过这个,但做了与View.INVISIBLE相同的功能,其中只有AppName隐藏但不隐藏AppbarIt,最好使用该porpose的CoordinatorLayout:take alook at[link]@Belzebub我很快就会处理这个问题。@Belzebub我已经尝试过了,但和以前一样的结果只有AppBar名称和3条水平线(抽屉指示器)隐藏,但AppBar仍然存在。