NestedScrollView无法正常工作

时间:2017-05-04 05:43:27

标签: android android-nestedscrollview

这是我的.xml文件

<?xml version="1.0" encoding="utf-8"?>
<android.support.v4.Nestedsrollview xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"


android:orientation="vertical"
    tools:context="com.example.rushabh123453.attendancepict.Attendance">




        <LinearLayout android:layout_weight="1" android:layout_height="0dp" android:layout_width="match_parent"
            android:orientation="vertical"
            android:background="@color/blue"
            android:paddingBottom="24dp">

            <TextView
                android:id="@+id/tv_attfinal"
              android:layout_width="match_parent"
                android:layout_height="200dp"
                android:text="78"

                android:gravity="center"
                android:textSize="120sp"
                android:textColor="@color/yellow"
                android:background="@color/blue"


            />

            <TextView
                android:layout_width="match_parent"
                android:layout_height="64dp"
                android:text="Hello"
                android:textColor="@color/yellow"
                android:textSize="40sp"
                android:background="@color/blue"
                android:gravity="center"/>


        </LinearLayout>
        <LinearLayout android:layout_weight="1" android:layout_height="0dp" android:layout_width="match_parent">

    <android.support.v7.widget.RecyclerView
        android:id="@+id/drawer_view"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"></android.support.v7.widget.RecyclerView>
            </LinearLayout>
</android.support.v4.Nestedsrollview >

我想使用nestedscrollview滚动整个布局,但是它显示非法声明的错误:只托管一个孩子。

我曾尝试将其中的每个孩子变成wrap_content,但这也是工作

build.gradle(app level)

apply plugin: 'com.android.application'

android {
    compileSdkVersion 23
    buildToolsVersion "25.0.2"

    defaultConfig {
        applicationId "com.example.rushabh123453.attendancepict"
        minSdkVersion 15
        targetSdkVersion 23
        versionCode 1
        versionName "1.0"
    }
    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }
}

dependencies {
    compile fileTree(dir: 'libs', include: ['*.jar'])
    testCompile 'junit:junit:4.12'
    compile 'com.android.support:appcompat-v7:23.4.0'
    compile 'com.android.support:design:23.1.1'
    compile 'com.android.support:recyclerview-v7:23.1.1'
    compile 'com.android.support:cardview-v7:23.1.1'
    compile 'org.jsoup:jsoup:1.7.3'
}

2 个答案:

答案 0 :(得分:0)

首先使用<android.support.v4.widget.NestedScrollView xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent" android:layout_height="match_parent" > <LinearLayout android:layout_height="match_parent" android:layout_width="match_parent" android:orientation="vertical" > <LinearLayout android:layout_height="wrap_content" android:layout_width="match_parent" android:orientation="vertical" android:paddingBottom="24dp"> <TextView android:id="@+id/tv_attfinal" android:layout_width="match_parent" android:layout_height="200dp" android:text="78" android:gravity="center" android:textSize="120sp" /> <TextView android:layout_width="match_parent" android:layout_height="64dp" android:text="Hello" android:textSize="40sp" android:gravity="center"/> </LinearLayout> <LinearLayout android:layout_weight="1" android:layout_height="0dp" android:layout_width="match_parent"> <android.support.v7.widget.RecyclerView android:id="@+id/drawer_view" android:layout_width="match_parent" android:layout_height="wrap_content"> </android.support.v7.widget.RecyclerView> </LinearLayout> </LinearLayout>

和xml的第二次更改:

   dependencies {
    compile fileTree(include: ['*.jar'], dir: 'libs')
    androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2', {
        exclude group: 'com.android.support', module: 'support-annotations'
    })

     compile 'com.android.support:recyclerview-v7:23.1.1'
    compile 'com.android.support:appcompat-v7:23.4.0'
    compile 'com.android.support:design:23.1.1'
    testCompile 'junit:junit:4.12'

  }

好的,现在试试这个..

更新了Build Gradle

替换它: -

html {
    min-height:100%;
    position:relative;
    height:auto;
}

body {
    padding-bottom:500px;
}

footer {
    position: absolute;
    bottom: 0; /** no effect **/
    min-height:500px;
    background: #000;
    width: 100%;
    z-index: 4;
}

答案 1 :(得分:0)

try, Put NestedScrollView in Main Linear layout

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical"
    tools:context="com.example.MainActivity">

    <android.support.v4.widget.NestedScrollView
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:scrollbars="none">

        <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:focusableInTouchMode="true"
            android:orientation="vertical">

              <TextView
            android:id="@+id/tv_attfinal"
            android:layout_width="match_parent"
            android:layout_height="200dp"
            android:text="78"
            android:gravity="center"
            android:textSize="120sp"
            />
        <TextView
            android:layout_width="match_parent"
            android:layout_height="64dp"
            android:text="Hello"
            android:textSize="40sp"
            android:gravity="center"/>

            <android.support.v7.widget.RecyclerView
                android:id="@+id/product_list"
                android:layout_width="match_parent"
                android:layout_height="match_parent"
                android:orientation="vertical"
                android:scrollbars="none" />

        </LinearLayout>
    </android.support.v4.widget.NestedScrollView>
</LinearLayout>