开发者

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.

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" 
      开发者_StackOverflow社区    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.

from 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; 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.


You must define empty 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" >
,...
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜