代码之家  ›  专栏  ›  技术社区  ›  Jakob

使NestedScrollView中的工具栏不可滚动

  •  0
  • Jakob  · 技术社区  · 7 年前

    Toolbar 内部 NestedScrollView 在 嵌套滚动视图 也有一些 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>
    

    所以我试着只包装 和 编辑文本 在一个 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>
    

    但它不起作用。

    非常 习俗 已使用。

    2 回复  |  直到 7 年前
        1
  •  1
  •   Veener Patrick Jackson    7 年前

    尝试相对布局

    <?xml version="1.0" encoding="utf-8"?>
    <RelativeLayout 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=".EmptyActivity">
    
        <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:contentInsetLeft="0dp"
            app:contentInsetRight="50dp"
            app:contentInsetStart="0dp"
            app:contentInsetStartWithNavigation="0dp"
            app:popupTheme="@style/AppTheme.PopupOverlay" />
    
        <ScrollView
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:layout_below="@+id/toolbar">
    
            <TextView
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:text="A long unimportant text" />
    
        </ScrollView>
    
    </RelativeLayout>
    
        2
  •  0
  •   Ben P.    7 年前

    ScrollView (和 NestedScrollView )威尔 允许 卷轴视图 在一个 wrap_content

    <?xml version="1.0" encoding="utf-8"?>
    <LinearLayout
        xmlns:android="http://schemas.android.com/apk/res/android"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:orientation="vertical">
    
        <android.support.v7.widget.Toolbar
            android:layout_width="match_parent"
            android:layout_height="wrap_content"/>
    
        <ScrollView
            android:layout_width="match_parent"
            android:layout_height="match_parent">
    
            <LinearLayout
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:orientation="vertical">
    
                <TextView
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:text="A long unimportant text"/>
    
                <!-- many more views -->
    
            </LinearLayout>
    
        </ScrollView>
    
    </LinearLayout>
    
    推荐文章