2017-05-04 45 views
-1

這是我的.xml文件NestedScrollView不工作

<?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(應用級)

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' 
} 
+0

NestedScrollView只能有一個孩子。你的NestedScrollView有兩個孩子。 –

+0

那麼可以做些什麼? –

+0

更新您的佈局,以便NestedScrollView只有一個孩子而不是兩個孩子。 –

回答

0

首先是使用android.support.v4.widget.NestedScrollView

,並在你的XML第二個變化:

<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> 

還好現在就來試試這個..

更新生成搖籃

替換此: -

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' 

    } 
+0

評論是不適合擴展討論;這個對話已經[轉移到聊天](http://chat.stackoverflow.com/rooms/143379/discussion-on-answer-by-andie-nestedscrollview-is-not-working)。 –

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> 
+0

下面的東西不工作 –

+0

你是否添加了setNestedScrollingEnabled(false)來回收視圖像這樣: - RecyclerView bestRecyclerView =(RecyclerView)findViewById(R.id.product_list); bestRecyclerView.setNestedScrollingEnabled(假); – user22

相關問題