简体   繁体   English

无法在线性+相对布局中使用ScrollView

[英]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. 以下是我的应用程序活动xml之一。它运行良好,但问题是当它变成横向模式时,我只能看到最上面的几个UI元素。所以我在其中添加了ScrollView。但是之后我的活动没有打开并崩溃。一个可以帮助我弄清楚我在添加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" 
              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. 您只能在ScrollView中添加1个视图。 So you only have to wrap all the stuff that's currently inside your ScrollView inside a LineraLayout for example. 因此,您只需要将ScrollView中当前包含的所有内容包装在LineraLayout中即可。

You need to have one more Linear or Relative layout inside the ScrollView as I have implemented it in your code. 正如我在您的代码中实现的那样,您需要在ScrollView中再有一个Linear或Relative布局。

<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>

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,以获得此博客中给出的答案之一。

<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. 缺少“ xmlns:android =“ http://schemas.android.com/apk/res/android”“。

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

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