简体   繁体   English

RelativeLayout scrollview

[英]RelativeLayout scrollview

I have an app with a few textboxes and editboxes. 我有一个带有几个文本框和编辑框的应用程序。 The app is working fine but when I am trying to add the scrollview element to see the lower part of app the application is forcibly closing. 该应用程序工作正常,但当我尝试添加scrollview元素以查看应用程序的下半部分时,应用程序强行关闭。

My code is: 我的代码是:

<?xml version="1.0" encoding="utf-8"?>
 <RelativeLayout  
     xmlns:android="http://schemas.android.com/apk/res/android"  
     android:layout_height="fill_parent"  
     android:layout_width="fill_parent"> 

    <ScrollView
    android:layout_width="fill_parent"
    android:layout_height="fill_parent">  

    <TextView  
         android:id="@+id/EditText01"  
         android:text="@string/type1"  
         android:layout_alignParentLeft="true"  
         android:layout_width="fill_parent"
         android:textSize="20sp"  
         android:layout_toLeftOf="@+id/Button01"  
         android:layout_height="wrap_content"></TextView>
     <EditText 
         android:id="@+id/Button01"  
         android:layout_width="100sp"  
         android:layout_alignParentRight="true"  
         android:layout_height="wrap_content"></EditText>

      <TextView  
         android:id="@+id/EditText02"  
         android:text="@string/type2"  
         android:layout_alignParentLeft="true"  
         android:layout_below="@id/EditText01"
         android:layout_width="fill_parent"  
         android:textSize="20sp"
         android:layout_toLeftOf="@+id/Button01"  
         android:layout_height="wrap_content"></TextView>
     <EditText 
         android:id="@+id/Button02"  
         android:layout_width="100sp"   
         android:layout_alignParentRight="true"  
         android:layout_below="@id/Button01"
         android:layout_height="wrap_content"></EditText>   

     <TextView  
         android:id="@+id/EditText03"  
         android:text="@string/type3"  
         android:layout_alignParentLeft="true"  
         android:layout_below="@id/EditText02"
         android:layout_width="fill_parent"  
         android:textSize="20sp"
         android:layout_toLeftOf="@+id/Button01"  
         android:layout_height="wrap_content"></TextView>
     <EditText 
         android:id="@+id/Button03"  
         android:layout_width="100sp"   
         android:layout_alignParentRight="true"  
         android:layout_below="@id/Button02"
         android:layout_height="wrap_content"></EditText>     

      <TextView  
         android:id="@+id/EditText04"  
         android:text="@string/property"  
         android:layout_below="@id/EditText03"
         android:layout_width="fill_parent"  
         android:textSize="20sp"
         android:layout_height="wrap_content"></TextView>     
       <Spinner 
        android:id="@+id/spinner"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:layout_below="@id/Button03"
        android:prompt="@string/property"></Spinner>

        <TextView
          android:id="@+id/EditText05"
          android:text="@string/propage"
          android:layout_below="@id/spinner"
              android:layout_width="fill_parent"
          android:textSize="20sp"
          android:layout_height="wrap_content"></TextView>  
        <Spinner
          android:id="@+id/widget"
          android:layout_width="fill_parent"
          android:layout_height="50sp"
          android:layout_below="@+id/EditText05"
          android:prompt="@string/propage"></Spinner>

          <TextView
          android:id="@+id/EditText06"
          android:text="@string/income"
          android:layout_alignParentLeft="true"
          android:layout_below="@+id/widget"
          android:layout_width="fill_parent"
          android:textSize="20sp"
          android:layout_toLeftOf="@+id/Button04" 
          android:layout_height="wrap_content"></TextView>   
          <EditText 
          android:id="@+id/Button04"  
          android:layout_width="100sp"   
          android:layout_alignParentRight="true"  
          android:layout_below="@id/widget"
          android:layout_height="wrap_content"></EditText>  

          <TextView
          android:id="@+id/EditText07"
          android:text="@string/borrow"
          android:layout_alignParentLeft="true"
          android:layout_below="@+id/EditText06"
          android:layout_width="fill_parent"
          android:textSize="20sp"
          android:layout_toLeftOf="@+id/Button05" 
          android:layout_height="wrap_content"></TextView>   
          <EditText 
          android:id="@+id/Button05"  
          android:layout_width="100sp"   
          android:layout_alignParentRight="true"  
          android:layout_below="@id/Button04"
          android:layout_height="wrap_content"></EditText>  

          <TextView
          android:id="@+id/EditText08"
          android:text="@string/interest"
          android:layout_alignParentLeft="true"
          android:layout_below="@+id/EditText07"
          android:layout_width="fill_parent"
          android:textSize="20sp"
          android:layout_toLeftOf="@+id/Button06" 
          android:layout_height="wrap_content"></TextView>   
          <EditText 
          android:id="@+id/Button06"  
          android:layout_width="100sp"   
          android:layout_alignParentRight="true"
          android:layout_below="@id/Button05"
          android:layout_height="wrap_content"></EditText>

          <Button
          android:id="@+id/Button07"
          android:layout_height="wrap_content"
          android:layout_width="wrap_content"
          android:text="@string/self_destruct"
          android:layout_below="@+id/EditText08"
          android:onClick="selfDestruct" />

          <TextView
          android:id="@+id/EditText09"
          android:text="@string/output1"
          android:layout_alignParentLeft="true"
          android:layout_below="@+id/Button07"
          android:layout_width="fill_parent"
          android:textSize="20sp"
          android:layout_toLeftOf="@+id/Button10" 
          android:layout_height="wrap_content"></TextView>   
          <TextView 
          android:id="@+id/EditText10"  
          android:text="@string/output2"
          android:layout_width="100sp"   
          android:layout_alignParentRight="true"
          android:layout_below="@id/Button07"
          android:layout_toRightOf="@+id/EditText09"
          android:layout_height="wrap_content"></TextView>

          <TextView
          android:id="@+id/EditText11"
          android:text="@string/output3"
          android:layout_alignParentLeft="true"
          android:layout_below="@+id/EditText09"
          android:layout_width="fill_parent"
          android:textSize="20sp"
          android:layout_toLeftOf="@+id/EditText12" 
          android:layout_height="wrap_content"></TextView>   
          <TextView 
          android:id="@+id/EditText12" 
          android:text="@string/output4" 
          android:layout_width="100sp"   
          android:layout_alignParentRight="true"
          android:layout_below="@id/EditText10"
          android:layout_height="wrap_content"></TextView>

          <TextView
          android:id="@+id/EditText13"
          android:text="@string/output5"
          android:layout_alignParentLeft="true"
          android:layout_below="@+id/EditText11"
          android:layout_width="fill_parent"
          android:textSize="20sp"
          android:layout_toLeftOf="@+id/EditText14" 
          android:layout_height="wrap_content"></TextView>   
          <TextView 
          android:id="@+id/EditText14"  
          android:text="@string/output6"
          android:layout_width="100sp"   
          android:layout_alignParentRight="true"
          android:layout_below="@id/EditText12"
          android:layout_height="wrap_content"></TextView>

          <TextView
          android:id="@+id/EditText15"
          android:text="@string/output7"
          android:layout_alignParentLeft="true"
          android:layout_below="@+id/EditText13"
          android:layout_width="fill_parent"
          android:textSize="20sp"
          android:layout_toLeftOf="@+id/Button16" 
          android:layout_height="wrap_content"></TextView>   
          <TextView 
          android:id="@+id/EditText16"  
          android:text="@string/output8"
          android:layout_width="100sp"   
          android:layout_alignParentRight="true"
          android:layout_below="@id/EditText14"
          android:layout_height="wrap_content"></TextView>


     </ScrollView>

     </RelativeLayout>

Please help. 请帮忙。 thanks in advance. 提前致谢。

Use the following format of layout 使用以下格式的布局

 <ScrollView>   

    <RelativeLayout> 
               // Use textviews used above here
    </RelativeLayout> 

 </ScrollView>  

A scrollview can, as far as i know, only have 1 child. 据我所知,滚动视图只能有一个孩子。 So you need to put all your Views in a LinearLayout or something, and add that to the scrollview. 因此,您需要将所有视图放在LinearLayout或其他内容中,并将其添加到scrollview中。

from http://developer.android.com/reference/android/widget/ScrollView.html 来自http://developer.android.com/reference/android/widget/ScrollView.html

A ScrollView is a FrameLayout, meaning you should place one child in it containing the entire contents to scroll; ScrollView是一个FrameLayout,意味着你应该在其中放置一个包含整个内容的子项进行滚动; this child may itself be a layout manager with a complex hierarchy of objects. 这个子本身可能是一个具有复杂对象层次结构的布局管理器。 A child that is often used is a LinearLayout in a vertical orientation, presenting a vertical array of top-level items that the user can scroll through. 经常使用的子项是垂直方向的LinearLayout,呈现用户可以滚动的顶级项目的垂直数组。

You must define empty textview... 你必须定义空的textview ...

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:background="@drawable/background"
    android:id="@+id/back"
    android:paddingRight="10dp"
    tools:context=".TaxActivity" >

<TextView
    android:id="@+id/tv1"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"/>

<ScrollView 
    android:id="@+id/scrollView1"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:layout_below="@+id/tv1" >
,...

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM