在这里我使用scrollVIEw获取滚动内容时,当我滚动内容如何隐藏工具栏时,请任何人告诉我如何获取
这是我的XMl代码
content_main.XML
<androID.support.v4.Widget.nestedScrollVIEwxmlns:app="http://schemas.androID.com/apk/res-auto"androID:layout_wIDth="match_parent"androID:layout_height="match_parent"xmlns:androID="http://schemas.androID.com/apk/res/androID"app:layout_behavior="@string/appbar_scrolling_vIEw_behavior"><linearLayout androID:orIEntation="vertical" androID:layout_wIDth="match_parent" androID:layout_height="match_parent"><linearLayout androID:paddingtop="?androID:attr/actionbarSize" androID:orIEntation="vertical" androID:layout_wIDth="match_parent" androID:layout_height="match_parent"> <TextVIEw androID:layout_marginleft="10dp" androID:layout_marginRight="10dp" androID:ID="@+ID/textone" androID:layout_wIDth="match_parent" androID:layout_height="match_parent" androID:textSize="23dp" androID:textStyle="bold" androID:text="hello world jheds sdjhs jds sjbs skJs ksJs kksJs ksj sdd dskd Js sk "/> <ImageVIEw androID:ID="@+ID/imge" androID:layout_wIDth="match_parent" androID:layout_height="250dp" androID:src="@drawable/imag_bg"/> <TextVIEw androID:ID="@+ID/texttwo" androID:layout_wIDth="match_parent" androID:layout_height="match_parent" androID:layout_marginleft="10dp" androID:layout_marginRight="10dp" androID:text="Pretty good,the Toolbar is moving along with the List and getting back just as we expect it to. This is thanks to the restrictions that we put on the mToolbarOffset variable. If we would omit checking if it’s bigger than 0 and lower than mToolbarHeight then when we would scroll up our List,the Toolbar would move along far away off the screen,so to show it back you would have to scroll the List down to 0. Right Now it just scrolls up to mToolbarHeight position and not more so it’s “sitting” right above the List all of the time and if we start scrolling down,we can see it immediately showing. up our List,we can see it immediately showing up our List,we can see it immediately showing It works pretty well,but this is not what we want. It feels weird that you can stop it in the mIDdle of the scroll and the Toolbar will stay half visible. Actually this is how it’s done in Google Play Games app which I consIDer as a BUG It works pretty well,but this is not what we want. It feels weird that you can stop it in the mIDdle of the scroll and the Toolbar will stay half visible. Actually this is how it’s done in Google Play Games app which I consIDer as a BUG It works pretty well,but this is not what we want. It feels weird that you can stop it in the mIDdle of the scroll and the Toolbar will stay half visible. Actually this is how it’s done in Google Play Games app which I consIDer as a BUG."/></linearLayout><VIEw androID:layout_wIDth="wrap_content" androID:layout_height="30dp" /><linearLayout androID:layout_wIDth="match_parent" androID:layout_height="match_parent"> <button androID:text="hai" androID:layout_wIDth="160dp" androID:layout_height="match_parent" /> <button androID:text="hello" androID:layout_wIDth="160dp" androID:layout_height="match_parent" /></linearLayout>
activity_main.xml中
<androID.support.design.Widget.AppbarLayout androID:layout_height="wrap_content" androID:layout_wIDth="match_parent" 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" />解决方法 你必须在你的两个布局中做很多改变.首先在activity_main.XML中使用CoordinatorLayout,如下所示(根据您的要求更改主题).
<?xml version="1.0" enCoding="utf-8"?><androID.support.design.Widget.CoordinatorLayout xmlns:androID="http://schemas.androID.com/apk/res/androID" xmlns:app="http://schemas.androID.com/apk/res-auto" androID:ID="@+ID/main_content" androID:layout_wIDth="match_parent" androID:layout_height="match_parent" androID:fitsSystemwindows="true"> <androID.support.design.Widget.AppbarLayout androID:layout_wIDth="match_parent" androID:layout_height="wrap_content" androID:theme="@style/themeOverlay.AppCompat.Dark.Actionbar"> <androID.support.v7.Widget.Toolbar androID:ID="@+ID/toolbar" androID:layout_wIDth="match_parent" androID:layout_height="?attr/actionbarSize" androID:background="?attr/colorPrimary" androID:theme="@style/themeOverlay.AppCompat.Dark.Actionbar" app:layout_scrollFlags="scroll|enteralways" app:popuptheme="@style/themeOverlay.AppCompat.light" /> </androID.support.design.Widget.AppbarLayout> <include layout="@layout/content_main" /></androID.support.design.Widget.CoordinatorLayout>
在content_main.XML中使用androID.support.v4.Widget.nestedScrollVIEw而不是ScrollVIEw.
也可以在androID.support.v4.Widget.nestedScrollVIEw中使用app:layout_behavior =“@ string / appbar_scrolling_vIEw_behavior”,如下所示.
<androID.support.v4.Widget.nestedScrollVIEw xmlns:app="http://schemas.androID.com/apk/res-auto" androID:layout_wIDth="match_parent" androID:layout_height="match_parent" xmlns:androID="http://schemas.androID.com/apk/res/androID" app:layout_behavior="@string/appbar_scrolling_vIEw_behavior"> <linearLayout androID:layout_wIDth="match_parent" androID:layout_height="match_parent" androID:orIEntation="vertical"> <TextVIEw androID:ID="@+ID/textone" androID:layout_wIDth="match_parent" androID:layout_height="match_parent" androID:text="hello world jheds sdjhs jds sjbs skJs ksJs kksJs ksj sdd dskd Js sk " androID:textSize="25dp" androID:textStyle="bold" /> /// Add your other code here </linearLayout> </androID.support.v4.Widget.nestedScrollVIEw>总结
以上是内存溢出为你收集整理的当我在android中滚动内容时如何隐藏ToolBar全部内容,希望文章能够帮你解决当我在android中滚动内容时如何隐藏ToolBar所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)