2017-04-06 127 views
1

尝试在android中取回编码。当我将另一个TextView添加到我的XML文件时,为什么我的程序崩溃?NestedScrollView崩溃Android

<?xml version="1.0" encoding="utf-8"?> 
<android.support.v4.widget.NestedScrollView 
    xmlns:android="http://schemas.android.com/apk/res/android" 
    xmlns:tools="http://schemas.android.com/tools" 
    xmlns:app="http://schemas.android.com/apk/res-auto" 
    app:layout_behavior="@string/appbar_scrolling_view_behavior" 
    tools:showIn="@layout/activity_comp_analysis" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    tools:context="com.example.oscarorellana.physicscalaculators.Math.CompAnalysis"> 


     <TextView 
     android:layout_width="match_parent" 
     android:layout_height="50dp" 
     android:text="Enter a complex number below" 
     android:textSize="20dp" 
     android:textStyle="bold" 
     /> 

     <TextView 
      android:layout_width="match_parent" 
      android:layout_height="wrap_content" 
      android:text="TEST" 
      /> 
</android.support.v4.widget.NestedScrollView> 

XML文件是我的一项Android活动中的内容文件。可能真的很基本,但我找不到这个错误。

回答

1

NestedScrollView应该只有一个直接child。添加一个新的Linear/Relative布局作为容器或TextViews

试试这个:

<NestedScrollView> 
    <LinearLayout> 
     <TextView> 
     <TextView> 
    <LinearLayout> 
<NestedScrollView> 

更新你的XML如下:

<?xml version="1.0" encoding="utf-8"?> 
<android.support.v4.widget.NestedScrollView 
    xmlns:android="http://schemas.android.com/apk/res/android" 
    xmlns:tools="http://schemas.android.com/tools" 
    xmlns:app="http://schemas.android.com/apk/res-auto" 
    app:layout_behavior="@string/appbar_scrolling_view_behavior" 
    tools:showIn="@layout/activity_comp_analysis" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    tools:context="com.example.oscarorellana.physicscalaculators.Math.CompAnalysis"> 

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

     <TextView 
      android:layout_width="match_parent" 
      android:layout_height="50dp" 
      android:text="Enter a complex number below" 
      android:textSize="20dp" 
      android:textStyle="bold" /> 

     <TextView 
      android:layout_width="match_parent" 
      android:layout_height="wrap_content" 
      android:text="TEST" /> 
    </LinearLayout> 

</android.support.v4.widget.NestedScrollView> 
+0

@Oscar Orellana如果此答案有效,请标记为接受的答案 – FAT

0
<?xml version="1.0" encoding="utf-8"?> 
<android.support.v4.widget.NestedScrollView 
    xmlns:android="http://schemas.android.com/apk/res/android" 
    xmlns:tools="http://schemas.android.com/tools" 
    xmlns:app="http://schemas.android.com/apk/res-auto" 
    app:layout_behavior="@string/appbar_scrolling_view_behavior" 
    tools:showIn="@layout/activity_comp_analysis" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    tools:context="com.example.oscarorellana.physicscalaculators.Math.CompAnalysis"> 

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


     <TextView 
     android:layout_width="match_parent" 
     android:layout_height="50dp" 
     android:text="Enter a complex number below" 
     android:textSize="20dp" 
     android:textStyle="bold" 
     /> 

     <TextView 
      android:layout_width="match_parent" 
      android:layout_height="wrap_content" 
      android:text="TEST" 
      /> 

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

试试这个代码:您需要添加滚动视图下孩子,那么只有滚动视图才会起作用:

<?xml version="1.0" encoding="utf-8"?> 
    <android.support.v4.widget.NestedScrollView 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" 
     app:layout_behavior="@string/appbar_scrolling_view_behavior" 
     tools:context="com.example.oscarorellana.physicscalaculators.Math.CompAnalysis" 
     tools:showIn="@layout/activity_comp_analysis"> 

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

      <TextView 
       android:layout_width="match_parent" 
       android:layout_height="50dp" 
       android:text="Enter a complex number below" 
       android:textSize="20dp" 
       android:textStyle="bold" /> 

      <TextView 
       android:layout_width="match_parent" 
       android:layout_height="wrap_content" 
       android:text="TEST" /> 
     </LinearLayout> 
    </android.support.v4.widget.NestedScrollView>