滚动型会导致应用程序崩溃 [英] ScrollView causes the App to crash

查看:200
本文介绍了滚动型会导致应用程序崩溃的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我测试了一些可用的传感器,和我显示每个传感器的值
一个TextView。

不过,当我附上一个滚动视图内的所有textviews的应用程序崩溃。

请注意:我的滚动视图已经被封闭在里面的LinearLayout

请找到.xml文件下方。

XML

 <滚动型
    机器人:isScrollContainer =真
    机器人:滚动条=垂直
    机器人:layout_height =FILL_PARENT
    机器人:layout_width =FILL_PARENT>< LinearLayout中的xmlns:机器人=htt​​p://schemas.android.com/apk/res/android
机器人:layout_width =WRAP_CONTENT
机器人:layout_height =WRAP_CONTENT
机器人:方向=垂直>    <的TextView
    机器人:ID =@ + ID /加速度
    机器人:layout_width =FILL_PARENT
    机器人:layout_height =WRAP_CONTENT
    机器人:文字=加速度/>
<的TextView
    机器人:ID =@ + ID / acc_tv01
    机器人:layout_width =FILL_PARENT
    机器人:layout_height =WRAP_CONTENT
    机器人:文字=X =/>
<的TextView
    机器人:ID =@ + ID / acc_tv01Value
    机器人:layout_width =FILL_PARENT
    机器人:layout_height =WRAP_CONTENT/>
<的TextView
    机器人:ID =@ + ID / acc_tv02
    机器人:layout_width =FILL_PARENT
    机器人:layout_height =WRAP_CONTENT
    机器人:文字=Y =/>
<的TextView
    机器人:ID =@ + ID / acc_tv02Value
    机器人:layout_width =FILL_PARENT
    机器人:layout_height =WRAP_CONTENT/>
<的TextView
    机器人:ID =@ + ID / acc_tv03
    机器人:layout_width =FILL_PARENT
    机器人:layout_height =WRAP_CONTENT
    机器人:文字=Z =/>
<的TextView
    机器人:ID =@ + ID / acc_tv03Value
    机器人:layout_width =FILL_PARENT
    机器人:layout_height =WRAP_CONTENT/>
< / LinearLayout中>< LinearLayout中的xmlns:机器人=htt​​p://schemas.android.com/apk/res/android
机器人:layout_width =WRAP_CONTENT
机器人:layout_height =WRAP_CONTENT
机器人:方向=垂直>    <的TextView
    机器人:ID =@ + ID /方向
    机器人:layout_width =FILL_PARENT
    机器人:layout_height =WRAP_CONTENT
    机器人:文字=方向/>
<的TextView
    机器人:ID =@ + ID / orient_tv01
    机器人:layout_width =FILL_PARENT
    机器人:layout_height =WRAP_CONTENT
    机器人:文字=X =/>
<的TextView
    机器人:ID =@ + ID / orient_tv01Value
    机器人:layout_width =FILL_PARENT
    机器人:layout_height =WRAP_CONTENT/>
<的TextView
    机器人:ID =@ + ID / orient_tv02
    机器人:layout_width =FILL_PARENT
    机器人:layout_height =WRAP_CONTENT
    机器人:文字=Y =/>
<的TextView
    机器人:ID =@ + ID / orient_tv02Value
    机器人:layout_width =FILL_PARENT
    机器人:layout_height =WRAP_CONTENT/>
<的TextView
    机器人:ID =@ + ID / orient_tv03
    机器人:layout_width =FILL_PARENT
    机器人:layout_height =WRAP_CONTENT
    机器人:文字=Z =/>
<的TextView
    机器人:ID =@ + ID / orient_tv03Value
    机器人:layout_width =FILL_PARENT
    机器人:layout_height =WRAP_CONTENT/>
< / LinearLayout中>< LinearLayout中的xmlns:机器人=htt​​p://schemas.android.com/apk/res/android
机器人:layout_width =WRAP_CONTENT
机器人:layout_height =WRAP_CONTENT
机器人:方向=垂直>    <的TextView
    机器人:ID =@ + ID /磁力计
    机器人:layout_width =FILL_PARENT
    机器人:layout_height =WRAP_CONTENT
    机器人:文字=磁力/>
<的TextView
    机器人:ID =@ + ID / magnet_tv01
    机器人:layout_width =FILL_PARENT
    机器人:layout_height =WRAP_CONTENT
    机器人:文字=X =/>
<的TextView
    机器人:ID =@ + ID / magnet_tv01Value
    机器人:layout_width =FILL_PARENT
    机器人:layout_height =WRAP_CONTENT/>
<的TextView
    机器人:ID =@ + ID / magnet_tv02
    机器人:layout_width =FILL_PARENT
    机器人:layout_height =WRAP_CONTENT
    机器人:文字=Y =/>
<的TextView
    机器人:ID =@ + ID / magnet_tv02Value
    机器人:layout_width =FILL_PARENT
    机器人:layout_height =WRAP_CONTENT/>
<的TextView
    机器人:ID =@ + ID / magnet_tv03
    机器人:layout_width =FILL_PARENT
    机器人:layout_height =WRAP_CONTENT
    机器人:文字=Z =/>
<的TextView
    机器人:ID =@ + ID / magnet_tv03Value
    机器人:layout_width =FILL_PARENT
    机器人:layout_height =WRAP_CONTENT/>
< / LinearLayout中>< LinearLayout中的xmlns:机器人=htt​​p://schemas.android.com/apk/res/android
机器人:layout_width =WRAP_CONTENT
机器人:layout_height =WRAP_CONTENT
机器人:方向=垂直>    <的TextView
    机器人:ID =@ + ID /陀螺
    机器人:layout_width =FILL_PARENT
    机器人:layout_height =WRAP_CONTENT
    机器人:文字=陀螺/>
<的TextView
    机器人:ID =@ + ID / gyro_tv01
    机器人:layout_width =FILL_PARENT
    机器人:layout_height =WRAP_CONTENT
    机器人:文字=X =/>
<的TextView
    机器人:ID =@ + ID / gyro_tv01Value
    机器人:layout_width =FILL_PARENT
    机器人:layout_height =WRAP_CONTENT/>
<的TextView
    机器人:ID =@ + ID / gyro_tv02
    机器人:layout_width =FILL_PARENT
    机器人:layout_height =WRAP_CONTENT
    机器人:文字=Y =/>
<的TextView
    机器人:ID =@ + ID / gyro_tv02Value
    机器人:layout_width =FILL_PARENT
    机器人:layout_height =WRAP_CONTENT/>
<的TextView
    机器人:ID =@ + ID / gyro_tv03
    机器人:layout_width =FILL_PARENT
    机器人:layout_height =WRAP_CONTENT
    机器人:文字=Z =/>
<的TextView
    机器人:ID =@ + ID / gyro_tv03Value
    机器人:layout_width =FILL_PARENT
    机器人:layout_height =WRAP_CONTENT/>
< / LinearLayout中>
< /滚动型>


解决方案

 <?XML版本=1.0编码=UTF-8&GT?;
< LinearLayout中的xmlns:机器人=htt​​p://schemas.android.com/apk/res/android
机器人:layout_width =FILL_PARENT
机器人:layout_height =FILL_PARENT
 机器人:背景=@绘制/背景
机器人:方向=垂直
 >< LinearLayout中的xmlns:机器人=htt​​p://schemas.android.com/apk/res/android
机器人:layout_width =match_parent
机器人:layout_height =50dip
机器人:方向=横向
机器人:背景=@绘制/导航栏> <的TableRow
    机器人:ID =@ + ID / tableRow1
    机器人:layout_width =WRAP_CONTENT
    机器人:layout_height =50dip
    机器人:重力=左> <按钮机器人:ID =@ + ID / detailback
 机器人:layout_width =70dip
 机器人:layout_height =39dip
 机器人:layout_marginTop =5dip
 机器人:layout_marginLeft =5dip
 机器人:背景=@绘制/后退
/>
< /&的TableRow GT;< / LinearLayout中>     <滚动型
     的xmlns:机器人=htt​​p://schemas.android.com/apk/res/android
     机器人:layout_width =FILL_PARENT
     机器人:layout_height =FILL_PARENT
     机器人:ID =@ + ID / Scroll1
   >
< LinearLayout中的xmlns:机器人=htt​​p://schemas.android.com/apk/res/android
机器人:layout_width =FILL_PARENT
机器人:layout_height =FILL_PARENT
机器人:方向=垂直
 >< LinearLayout中的xmlns:机器人=htt​​p://schemas.android.com/apk/res/android
机器人:layout_width =FILL_PARENT
机器人:layout_marginTop =20像素
机器人:layout_height =100px的机器人:方向=横向
 >    < ImageView的
        机器人:ID =@ + ID / Dicimage
        机器人:layout_width =130px
        机器人:layout_height =100px的
        机器人:填充=1DP/>
    <的TextView
        机器人:ID =@ + ID / DictionaryName
        机器人:TEXTSIZE =25像素
        机器人:文字样式=大胆
        机器人:比重=中心
        机器人:layout_width =250像素
        机器人:layout_height =100px的
        机器人:文字颜色=#FFF
        />    <按钮
        机器人:ID =@ + ID /买入
        机器人:背景=@绘制/买入
        机器人:文字=买入
        机器人:TEXTSIZE =20像素
        机器人:文字样式=大胆
        机器人:文字颜色=#FFF
        机器人:layout_width =90像素
        机器人:layout_height =35px
         /> < / LinearLayout中>    < LinearLayout中的xmlns:机器人=htt​​p://schemas.android.com/apk/res/android
机器人:layout_width =FILL_PARENT
机器人:layout_height =350像素
机器人:layout_marginTop =20像素
机器人:layout_marginLeft =5像素
机器人:layout_marginRight =5像素
机器人:背景=@绘制/箱
机器人:方向=垂直
 >
    <滚动型
     的xmlns:机器人=htt​​p://schemas.android.com/apk/res/android
     机器人:ID =@ + ID / Scroll2
     机器人:layout_width =FILL_PARENT
     机器人:fillViewport =真
     机器人:layout_height =WRAP_CONTENT
   >    < LinearLayout中的xmlns:机器人=htt​​p://schemas.android.com/apk/res/android
机器人:layout_width =FILL_PARENT
机器人:layout_height =250像素
机器人:layout_marginTop =20像素
机器人:方向=垂直
 >
    <的TextView
        机器人:ID =@ + ID /说明
        机器人:文字颜色=#FFF
        机器人:文字=描述:
        机器人:layout_marginLeft =15像素
        机器人:TEXTSIZE =20像素
        机器人:文字样式=大胆
        机器人:layout_width =match_parent
        机器人:layout_height =match_parent
        />
    <的TextView
        机器人:ID =@ + ID /说明1
        机器人:文字颜色=#FFF
        机器人:layout_marginLeft =15像素
        机器人:TEXTSIZE =20像素
        机器人:layout_width =match_parent
        机器人:layout_height =match_parent
        />   < / LinearLayout中>     < /滚动型>    < / LinearLayout中>  < LinearLayout中的xmlns:机器人=htt​​p://schemas.android.com/apk/res/android
机器人:layout_width =FILL_PARENT
机器人:layout_marginTop =20像素
机器人:比重=中心
机器人:layout_height =520px
机器人:方向=横向>   < android.support.v4.view.ViewPager
         机器人:layout_width =320像素
         机器人:layout_height =480像素
         机器人:ID =@ + ID / myfivepanelpager
        />  < / LinearLayout中>
   < / LinearLayout中>   < /滚动型>    < / LinearLayout中>

在这里,我又scrollview.it内使用滚动视图工作fine..it 5月帮助U

I'm testing the some of the sensors available, and i display the values of each sensor in a textview.

But When I enclosed all the textviews inside a scrollView the App crashed.

Note: my scrollView is already enclosed inside a linearLayout

Please find below the .xml file.

XML:

<ScrollView
    android:isScrollContainer="true"
    android:scrollbars="vertical"
    android:layout_height="fill_parent"
    android:layout_width="fill_parent">

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="vertical" >

    <TextView
    android:id="@+id/accelerometer"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:text="    Accelerometer  " />
<TextView
    android:id="@+id/acc_tv01"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:text="X = " /> 
<TextView
    android:id="@+id/acc_tv01Value"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content" />
<TextView
    android:id="@+id/acc_tv02"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:text="Y = " />
<TextView
    android:id="@+id/acc_tv02Value"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content" />
<TextView
    android:id="@+id/acc_tv03"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:text="Z = " />
<TextView
    android:id="@+id/acc_tv03Value"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content" />
</LinearLayout>

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="vertical" >

    <TextView
    android:id="@+id/Orientation"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:text="    Orientation  " />
<TextView
    android:id="@+id/orient_tv01"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:text="X = " /> 
<TextView
    android:id="@+id/orient_tv01Value"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content" />
<TextView
    android:id="@+id/orient_tv02"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:text="Y = " />
<TextView
    android:id="@+id/orient_tv02Value"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content" />
<TextView
    android:id="@+id/orient_tv03"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:text="Z = " />
<TextView
    android:id="@+id/orient_tv03Value"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content" />
</LinearLayout>

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="vertical" >

    <TextView
    android:id="@+id/Magnetometer"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:text="    Magnetometer  " />
<TextView
    android:id="@+id/magnet_tv01"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:text="X = " /> 
<TextView
    android:id="@+id/magnet_tv01Value"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content" />
<TextView
    android:id="@+id/magnet_tv02"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:text="Y = " />
<TextView
    android:id="@+id/magnet_tv02Value"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content" />
<TextView
    android:id="@+id/magnet_tv03"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:text="Z = " />
<TextView
    android:id="@+id/magnet_tv03Value"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content" />
</LinearLayout>

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="vertical" >

    <TextView
    android:id="@+id/Gyroscope"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:text="    Gyroscope  " />
<TextView
    android:id="@+id/gyro_tv01"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:text="X = " /> 
<TextView
    android:id="@+id/gyro_tv01Value"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content" />
<TextView
    android:id="@+id/gyro_tv02"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:text="Y = " />
<TextView
    android:id="@+id/gyro_tv02Value"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content" />
<TextView
    android:id="@+id/gyro_tv03"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:text="Z = " />
<TextView
    android:id="@+id/gyro_tv03Value"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content" />
</LinearLayout>
</ScrollView>

解决方案

<?xml version="1.0" encoding="utf-8"?>


<LinearLayout  xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
 android:background="@drawable/background"
android:orientation="vertical"
 >

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="50dip"
android:orientation="horizontal"
android:background="@drawable/navbar" >  

 <TableRow
    android:id="@+id/tableRow1"
    android:layout_width="wrap_content"
    android:layout_height="50dip"
    android:gravity="left">        

 <Button  android:id="@+id/detailback"
 android:layout_width="70dip"
 android:layout_height="39dip"
 android:layout_marginTop="5dip"
 android:layout_marginLeft="5dip"
 android:background="@drawable/back"   
/>       
</TableRow>

</LinearLayout>

     <ScrollView
     xmlns:android="http://schemas.android.com/apk/res/android"
     android:layout_width="fill_parent"
     android:layout_height="fill_parent"
     android:id="@+id/Scroll1"
   >


<LinearLayout  xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical"
 >

<LinearLayout  xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_marginTop="20px"
android:layout_height="100px"

android:orientation="horizontal" 
 >

    <ImageView
        android:id="@+id/Dicimage"
        android:layout_width="130px"
        android:layout_height="100px"
        android:padding="1dp"/>


    <TextView 
        android:id="@+id/DictionaryName"
        android:textSize="25px"
        android:textStyle="bold"
        android:gravity="center"
        android:layout_width="250px"
        android:layout_height="100px"
        android:textColor="#FFF"
        />

    <Button
        android:id="@+id/buy"
        android:background="@drawable/buy"
        android:text="Buy"
        android:textSize="20px"
        android:textStyle="bold"
        android:textColor="#FFF"
        android:layout_width="90px"
        android:layout_height="35px"


         />

 </LinearLayout>

    <LinearLayout  xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="350px"
android:layout_marginTop="20px"
android:layout_marginLeft="5px"
android:layout_marginRight="5px"
android:background="@drawable/box"
android:orientation="vertical"
 >
    <ScrollView
     xmlns:android="http://schemas.android.com/apk/res/android"
     android:id="@+id/Scroll2"
     android:layout_width="fill_parent"
     android:fillViewport="true"
     android:layout_height="wrap_content"
   >

    <LinearLayout  xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="250px"
android:layout_marginTop="20px"
android:orientation="vertical"
 >
    <TextView 
        android:id="@+id/Description"
        android:textColor="#FFF"
        android:text="Description: "
        android:layout_marginLeft="15px"
        android:textSize="20px"
        android:textStyle="bold"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        />


    <TextView 
        android:id="@+id/Description1"
        android:textColor="#FFF"
        android:layout_marginLeft="15px"
        android:textSize="20px"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        />

   </LinearLayout>

     </ScrollView>

    </LinearLayout>



  <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_marginTop="20px"
android:gravity="center"
android:layout_height="520px"
android:orientation="horizontal">

   <android.support.v4.view.ViewPager     
         android:layout_width="320px"
         android:layout_height="480px"
         android:id="@+id/myfivepanelpager"   
        />  

  </LinearLayout>


   </LinearLayout>

   </ScrollView>

    </LinearLayout>

here i used scrollview within another scrollview.it works fine..it may helps u

这篇关于滚动型会导致应用程序崩溃的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆