当 </ScrollView> 时应用程序崩溃放在最后 [英] App crashes when </ScrollView> put at end

查看:30
本文介绍了当 </ScrollView> 时应用程序崩溃放在最后的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

完整文件如下:尝试在 android 设备中垂直滚动,但将滚动视图放在文件末尾会导致崩溃

full file follows: trying to have full scroll vertical in android device but putting scroll view at end of file produces crash

   `<?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"
     android:paddingBottom="@dimen/activity_vertical_margin"
     android:paddingLeft="@dimen/activity_horizontal_margin"
     android:paddingRight="@dimen/activity_horizontal_margin"
     android:paddingTop="@dimen/activity_vertical_margin"
     app:layout_behavior="@string/appbar_scrolling_view_behavior"
     tools:context="com.cancunsteve.aboutcancunsteve.MainActivity"
     tools:showIn="@layout/activity_main">


    <ScrollView
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:id="@+id/scrollView"
    android:layout_alignParentStart="true"
    android:layout_marginTop="56dp" />
    <ImageView android:id="@+id/imageView"
    android:layout_column="1"
    android:background="@mipmap/lpussy"
    android:contentDescription='android:ContentDescription="@string/desc"'
    tools:ignore="HardcodedText"
    android:layout_width="200dp"
    android:layout_height="230dp" />


    <TextView
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:text="serving good people with special deals. "
    android:id="@+id/text1"
    android:layout_alignTop="@+id/imageView"
    android:layout_alignParentRight="true"
    android:layout_alignParentEnd="true"
    android:background="#ffffff"
    android:foreground="#05ffffff"
    android:foregroundTint="#03ffffff"
    android:textColor="#000000" />



    <EditText
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:id="@+id/editText2"
    android:text="Cancun, Playa del Carmen, Chichen Itza."
    android:layout_below="@+id/text1"
    android:layout_alignParentRight="true"
    android:layout_alignParentEnd="true" />

    <EditText
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:id="@+id/editText"
    android:text="Holbox, Taxco, Palenque, Acapulco, Guanajuato,  
    Monterrey, Tenacatita, Mascota"
    android:layout_below="@+id/editText2"
    android:layout_alignParentLeft="true"
    android:layout_alignParentStart="true" />

<ImageButton
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:id="@+id/imageButton"
    android:layout_below="@+id/editText3"
    android:layout_alignParentLeft="true"
    android:layout_alignParentStart="true"
    android:background="@mipmap/campa"
    tools:ignore="ContentDescription"
    android:layout_alignBottom="@+id/editText5" />

    <EditText
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:inputType="textEmailAddress"
    android:ems="10"
    android:id="@+id/editText3"
    android:text="thewebmaster@cancunsteve.com"
    android:layout_below="@+id/editText"
    android:layout_alignParentLeft="true"
    android:layout_alignParentStart="true"
    android:layout_alignRight="@+id/editText"
    android:layout_alignEnd="@+id/editText" />

    <EditText
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:inputType="phone"
    android:ems="10"
    android:id="@+id/editText4"
    android:text="       011 52 998 8873919"
    android:layout_below="@+id/editText3"
    android:layout_alignParentLeft="true"
    android:layout_alignParentStart="true"
    android:layout_marginLeft="42dp"
    android:layout_marginStart="32dp" />

    <EditText
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:id="@+id/editText5"
    android:text="be sure to visit us for discounts on your hotel bookings"
    android:layout_below="@+id/editText4"
    android:layout_toRightOf="@+id/scrollView"
    android:layout_toEndOf="@+id/scrollView" />

    <TextView
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:text="click buttons multiple times to change state"
    android:id="@+id/textView2"
    android:layout_below="@+id/imageButton" />


   </RelativeLayout>`

当在相对布局文件后添加 ScrollView 时不会打开把它放在括号中,然后用反斜杠/也许我在第一个和最后一个 ScrollView 之间放了什么?我注意到在你展示的例子中,滚动视图出现在开头.

when ScrollView added after Relative layout file won't open put it in brackets proceeded with backslash / perhaps something I put in between the first and last ScrollView? I noticed in the examples you show, scrollview appears in the beginning.

推荐答案

根据你的 xml,最好交换 xml 文件中的前两个元素标签.

As per your xml, Its better to swap the top two element tags in your xml file.

这样你的RelativeLayout就会成为ScrollView的子元素.并且您不必编辑剩余的布局元素

So that yor RelativeLayout will become a child of ScrollView. and You dont have to edit your remaining layout elements

结果将是..

< ScrollView
     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"
     android:id="@+id/scrollView"
     android:paddingBottom="@dimen/activity_vertical_margin"
     android:paddingLeft="@dimen/activity_horizontal_margin"
     android:paddingRight="@dimen/activity_horizontal_margin"
     android:paddingTop="@dimen/activity_vertical_margin"
     app:layout_behavior="@string/appbar_scrolling_view_behavior"
     tools:context="com.cancunsteve.aboutcancunsteve.MainActivity"
     tools:showIn="@layout/activity_main">




    <RelativeLayout
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_alignParentStart="true"
    android:layout_marginTop="56dp" >

它应该像..

</RelativeLayout>
</ScrollView>

补充:您可以使用 LinearLayout 替换相对布局以消除 scrollView 错误...

Addition: You can replace the Relative Layout with a LinearLayout to get Rid of scrollView Errors...

<?xml version="1.0" encoding="utf-8"?>
<ScrollView
    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:paddingBottom="@dimen/activity_vertical_margin"
    android:paddingLeft="@dimen/activity_horizontal_margin"
    android:paddingRight="@dimen/activity_horizontal_margin"
    android:paddingTop="@dimen/activity_vertical_margin"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:id="@+id/scrollView">


    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_alignParentStart="true"
        android:orientation="vertical"
        android:layout_marginTop="56dp" >

    <ImageView android:id="@+id/imageView"
        android:layout_column="1"
        android:background="#ff0f"
        android:contentDescription='android:ContentDescription="@string/desc"'
        tools:ignore="HardcodedText"
        android:layout_width="200dp"
        android:layout_height="230dp" />


    <TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="serving good people with special deals. "
        android:id="@+id/text1"
        android:layout_alignTop="@+id/imageView"
        android:layout_alignParentRight="true"
        android:layout_alignParentEnd="true"
        android:background="#ffffff"
        android:foreground="#05ffffff"
        android:foregroundTint="#03ffffff"
        android:textColor="#000000" />



    <EditText
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:id="@+id/editText2"
        android:text="Cancun, Playa del Carmen, Chichen Itza."
        android:layout_below="@+id/text1"
        android:layout_alignParentRight="true"
        android:layout_alignParentEnd="true" />

    <EditText
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:id="@+id/editText"
        android:text="Holbox, Taxco, Palenque, Acapulco, Guanajuato,
    Monterrey, Tenacatita, Mascota"
        android:layout_below="@+id/editText2"
        android:layout_alignParentLeft="true"
        android:layout_alignParentStart="true" />

    <ImageButton
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:id="@+id/imageButton"
        android:layout_below="@+id/editText3"
        android:layout_alignParentLeft="true"
        android:layout_alignParentStart="true"
        android:background="#f0f0"
        tools:ignore="ContentDescription"
        android:layout_alignBottom="@+id/editText5" />

    <EditText
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:inputType="textEmailAddress"
        android:ems="10"
        android:id="@+id/editText3"
        android:text="thewebmaster@cancunsteve.com"
        android:layout_below="@+id/editText"
        android:layout_alignParentLeft="true"
        android:layout_alignParentStart="true"
        android:layout_alignRight="@+id/editText"
        android:layout_alignEnd="@+id/editText" />

    <EditText
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:inputType="phone"
        android:ems="10"
        android:id="@+id/editText4"
        android:text="       011 52 998 8873919"
        android:layout_below="@+id/editText3"
        android:layout_alignParentLeft="true"
        android:layout_alignParentStart="true"
        android:layout_marginLeft="42dp"
        android:layout_marginStart="32dp" />

    <EditText
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:id="@+id/editText5"
        android:text="be sure to visit us for discounts on your hotel bookings"
        android:layout_below="@+id/editText4" />

    <TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="click buttons multiple times to change state"
        android:id="@+id/textView2"
        android:layout_below="@+id/imageButton" />

    </LinearLayout>

</ScrollView>

这篇关于当 &lt;/ScrollView&gt; 时应用程序崩溃放在最后的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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