【发布时间】:2018-11-02 20:54:50
【问题描述】:
我在NestedScrollView 中有一个自定义Toolbar。
在NestedScrollView中也有一些TextViews和Edittexts。
我的问题是不仅TextViews 和Edittexts 被滚动,Toolbar 也被滚动。
滚动NestedScrollView 中的Toolbar 是合乎逻辑的。
我想要一个自定义的Toolbar,其顶部有一个绝对位置,并且TextViews 和Edittexts 可滚动。
这是我正在使用的代码:
<android.support.v4.widget.NestedScrollView
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent">
<android.support.v7.widget.Toolbar
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="@+id/toolbar"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
android:background="#ffffff"
android:elevation="5dp"
android:minHeight="?attr/actionBarSize"
app:contentInsetEnd="50dp"
app:contentInsetRight="50dp"
app:contentInsetLeft="0dp"
app:contentInsetStart="0dp"
app:contentInsetStartWithNavigation="0dp"
app:popupTheme="@style/AppTheme.PopupOverlay">
</android.support.v7.widget.Toolbar>
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="A long unimportant text"/>
</android.support.v4.widget.NestedScrollView>
所以我尝试只将TextViews 和Edittexts 包装在ScrollView 中,例如:
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent">
<android.support.v7.widget.Toolbar
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="@+id/toolbar"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
android:background="#ffffff"
android:elevation="5dp"
android:minHeight="?attr/actionBarSize"
app:contentInsetEnd="50dp"
app:contentInsetRight="50dp"
app:contentInsetLeft="0dp"
app:contentInsetStart="0dp"
app:contentInsetStartWithNavigation="0dp"
app:popupTheme="@style/AppTheme.PopupOverlay">
</android.support.v7.widget.Toolbar>
<ScrollView
android:layout_width="match_parent"
android:layout_height="match_parent">
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="A long unimportant text"/>
</ScrollView>
</LinearLayout>
但它不起作用。
使用自定义
Toolbar非常很重要。
【问题讨论】:
-
看看折叠工具栏。?
-
你没有关闭工具栏
-
@Veener 我只是在问题中忘记了它,但在我的代码中却没有。但无论如何感谢您的提示,我编辑了我的问题。
-
您的 ScrollView 中是否有多个 TextView?
-
只是为了确定......在您将 TextView 包装在滚动视图中的第二种方法中,整个布局是包装在 nestedScroll 内还是线性布局是根布局? @雅各布
标签: android scrollview android-toolbar android-nestedscrollview nestedscrollview