开发者

unable to use ScrollView in linear + relative layout

Following is one of my application activity xml.Its running fine but the problem was when it turns in Landscape mode i see only top few UI elements.So i added ScrollView in it .But after that my activity is not opening and crashing.Please some one help me figure out what i am doing wrong in adding a ScrollView.

Thanks

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


    <ScrollView android:id="@+id/scroll" android:layout_width="fill_parent"
    android:layout_height="wrap_content">

    <ImageView
            android:src="@drawable/logo"
            android:adjustViewBounds="true"
            android:scaleType="center"
            android:layout_gravity="center_vertical|center_horizontal"            
            android:layout_width="wrap_content"
            android:layout_height="wrap_content" />

    <TextView
        android:id="@+id/rishi_idlabel"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text = "Email address:"
        android:textColor = "#000000"
        android:textSize="15sp"
        android:paddingLeft="10px"
        android:paddingRight="5px"
    />

    <EditText android:id ="@+id/custid"
            android:hint = "ID"
            android:layout_gravity="center_vertical|center_horizontal"
            android:scaleType="center"
            android:inputType = "phone"
            android:singleLine = "true"
            android:layout_width="fill_parent"
            android:layout_height="wrap_content" 
            android:layout_marginLeft = "10px"
            android:layout_marginRight = "10px"
            />              

    <TextView
        android:id="@+id/pass"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text = "Password:"
        android:textColor = "#000000"
        android:textSize="15sp"
        android:paddingLeft="10px"
        android:paddingRight="5px"
    />

    <EditText android:id ="@+id/password"
            android:hint="Password"
            android:layout_gravity="center_vertical|center_horizontal"
            android:password = "true"
            android:singleLine = "true"         
            android:scaleType="center"
            android:layout_width="fill_parent"
            android:layout_height="wrap_content" 
            android:layout_marginLeft = "10px"
            android:layout_marginRight = "10px"
            />

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
              android:layout_width="wrap_content" 
      开发者_如何学Go        android:layout_height="wrap_content"
               android:layout_marginTop = "10px"
              android:background="#FFFFFF" 
              android:orientation="horizontal"> 

    <Button android:id="@+id/loginButton"
            android:layout_gravity="left"
            android:layout_width="180sp"
            android:layout_height="wrap_content"
            android:layout_marginLeft = "10px"
            android:layout_marginTop = "10px"
            android:text="Login"/>


     <TextView
        android:id="@+id/passforgot"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text = "forgot password"
        android:clickable = "true"
        android:focusable = "true"
        android:textColor = "#0000FF"
        android:layout_marginTop = "10px"
        android:textSize="15sp"
        android:paddingLeft="3px"
        android:paddingRight="3px"

    />
       </LinearLayout> 

 <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
              android:layout_width="wrap_content" 
              android:layout_height="wrap_content"
              android:layout_marginTop = "10px"
              android:background="#FFFFFF" 
              android:orientation="horizontal">          
     <TextView
        android:id="@+id/newaccount"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text = "Dont have an account yet?"
        android:textColor = "#000000"
        android:layout_marginLeft = "10px"
        android:layout_marginTop = "10px"
        android:textSize="15sp"
        android:paddingLeft="3px"
        android:paddingRight="3px"
    />     

        <Button android:id="@+id/signup"
            android:layout_gravity="right"
            android:layout_width="100sp"
            android:layout_height="wrap_content"
            android:layout_marginLeft = "10px"
            android:layout_marginTop = "10px"
            android:text="Sign-Up"/>

     </LinearLayout>  
     </ScrollView>

</LinearLayout>


**Here It is Your Answer : This is your editable code : **

<ScrollView xmlns:android="http://schemas.android.com/apk/res/android" 
   android:id="@+id/scroll" android:layout_width="fill_parent"
    android:layout_height="fill_parent" android:background="#FFFFFF">
    <LinearLayout 
        android:layout_width="fill_parent" 
        android:layout_height="fill_parent"
        android:orientation="vertical"> 
    <ImageView android:src="@drawable/logo"
        android:adjustViewBounds="true"
        android:scaleType="center"
        android:layout_gravity="center_vertical|center_horizontal"            
        android:layout_width="wrap_content"
        android:layout_height="wrap_content" />
   <TextView
        android:id="@+id/rishi_idlabel"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text = "Email address:"
        android:textColor = "#000000"
        android:textSize="15sp"
        android:paddingLeft="10px"
        android:paddingRight="5px"/>
   <EditText android:id ="@+id/custid"
        android:hint = "ID"
        android:layout_gravity="center_vertical|center_horizontal"
        android:scaleType="center"
        android:inputType = "phone"
        android:singleLine = "true"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content" 
        android:layout_marginLeft = "10px"
        android:layout_marginRight = "10px"/>              
   <TextView
        android:id="@+id/pass"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text = "Password:"
        android:textColor = "#000000"
        android:textSize="15sp"
        android:paddingLeft="10px"
        android:paddingRight="5px"/>
  <EditText android:id ="@+id/password"
        android:hint="Password"
        android:layout_gravity="center_vertical|center_horizontal"
        android:password = "true"
        android:singleLine = "true"         
        android:scaleType="center"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content" 
        android:layout_marginLeft = "10px"
        android:layout_marginRight = "10px"/>
  <LinearLayout 
        android:layout_width="wrap_content" 
        android:layout_height="wrap_content"
        android:layout_marginTop = "10px"
        android:orientation="horizontal"> 

  <Button android:id="@+id/loginButton"
        android:layout_gravity="left"
        android:layout_width="180sp"
        android:layout_height="wrap_content"
        android:layout_marginLeft = "10px"
        android:layout_marginTop = "10px"
        android:text="Login"/>
  <TextView
        android:id="@+id/passforgot"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text = "forgot password"
        android:clickable = "true"
        android:focusable = "true"
        android:textColor = "#0000FF"
        android:layout_marginTop = "10px"
        android:textSize="15sp"
        android:paddingLeft="3px"
        android:paddingRight="3px"/>
   </LinearLayout> 
   <LinearLayout 
        android:layout_width="wrap_content" 
        android:layout_height="wrap_content"
        android:layout_marginTop = "10px"
        android:orientation="horizontal">          
        <TextView
             android:id="@+id/newaccount"
             android:layout_width="wrap_content"
             android:layout_height="wrap_content"
             android:text = "Dont have an account yet?"
             android:textColor = "#000000"
             android:layout_marginLeft = "10px"
             android:layout_marginTop = "10px"
             android:textSize="15sp"
             android:paddingLeft="3px"
             android:paddingRight="3px"/>     
        <Button android:id="@+id/signup"
             android:layout_gravity="right"
             android:layout_width="100sp"
             android:layout_height="wrap_content"
             android:layout_marginLeft = "10px"
             android:layout_marginTop = "10px"
             android:text="Sign-Up"/>
   </LinearLayout>  
</LinearLayout>
</ScrollView>

But you don't use the good programming skills,your code is not in proper format ,keep in mind give proper format


You can only add 1 View inside a ScrollView. So you only have to wrap all the stuff that's currently inside your ScrollView inside a LineraLayout for example.


Thanks guys for your quick replies finally able to sort my problem. Actually i was using this code for ScrollView for one of the answres given in this blog.

<ScrollView android:id="@+id/scroll" android:layout_width="fill_parent"
                    android:layout_height="wrap_content">
 </ScrollView>

This code was crashing.So i checked the Docs and figured out that there was difference between two by which my code was not running.

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

"xmlns:android="http://schemas.android.com/apk/res/android"" was missing.


You need to have one more Linear or Relative layout inside the ScrollView as I have implemented it in your code.

<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"  android:id="@+id/scroll" android:layout_width="fill_parent" android:layout_height="wrap_content"> 
    <LinearLayout                android:layout_width="fill_parent"        android:layout_height="fill_parent"    android:orientation="vertical"    >    

    <!-- You can write your further code as written in your xml code here or you can do whatever you want to do inside the scrollview here-->


     </LinearLayout>             
     </ScrollView>
0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜