0

I am new to android.Wen I run this apk file in my phone,it runs and wen I rotate for a horizontal view,it shows only half a page and if I try to scroll,it doesnt scroll.I tried a lot using ScrollView.It is not getting Implemented.the error wch occurs is :"activity_main.xml: ScrollView can host only one direct child".Can someone suggest me how to solve it??

  <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
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"
tools:context=".MainActivity" >

<TextView
    android:id="@+id/textView1"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_alignBottom="@+id/imageView1"
    android:layout_centerHorizontal="true"
    android:text="LOGIN"
    android:textSize="30sp"
    android:textStyle="bold" />

<TextView
     android:id="@+id/textView1"
     android:layout_width="wrap_content"
     android:layout_height="wrap_content"
     android:layout_alignParentLeft="true"
     android:layout_below="@+id/imageView1"
     android:layout_marginTop="49dp"
     android:text="Username"
     android:textSize="20sp" />

<TextView
     android:id="@+id/textView2"
     android:layout_width="wrap_content"
     android:layout_height="wrap_content"
     android:layout_alignLeft="@+id/textView1"
     android:layout_below="@+id/editText3"
     android:layout_marginTop="17dp"
     android:text="Password"
     android:textSize="20sp" />

 <TextView
     android:id="@+id/link_to_register"
     android:layout_width="fill_parent"
     android:layout_height="wrap_content"
     android:layout_alignRight="@+id/button1"
     android:layout_below="@+id/button1"
     android:layout_marginTop="14dp"
     android:gravity="center"
     android:text="Forgot Password"
     android:textColor="#0b84aa"
     android:textSize="20dip" />



 <EditText
     android:id="@+id/editText1"
     android:layout_width="wrap_content"
     android:layout_height="wrap_content"
     android:layout_below="@+id/textView1"
     android:layout_marginTop="26dp"
     android:layout_toLeftOf="@+id/textView1"
     android:ems="10" >

     <requestFocus />
 </EditText>

 <EditText
     android:id="@+id/editText3"
     android:layout_width="fill_parent"
     android:layout_height="wrap_content"
     android:layout_alignBottom="@+id/textView1"
     android:layout_alignLeft="@+id/editText4"
     android:ems="10"
     android:inputType="textEmailAddress" />

 <EditText
     android:id="@+id/editText2"
     android:layout_width="wrap_content"
     android:layout_height="wrap_content"
     android:layout_below="@+id/textView1"
     android:layout_marginTop="42dp"
     android:layout_toLeftOf="@+id/textView1"
     android:ems="10" />

 <EditText
     android:id="@+id/editText4"
     android:layout_width="fill_parent"
     android:layout_height="wrap_content"
     android:layout_alignBaseline="@+id/textView2"
     android:layout_alignBottom="@+id/textView2"
     android:layout_alignParentRight="true"
     android:layout_marginLeft="100dp"
     android:ems="10"
     android:inputType="textPassword" />

 <Button
     android:id="@+id/button1"
     android:layout_width="wrap_content"
     android:layout_height="wrap_content"
     android:layout_alignLeft="@+id/editText3"
     android:layout_below="@+id/editText4"
     android:layout_marginTop="23dp"
     android:background="#9ACD32"
     android:text="Log In" />


 <ImageView
     android:id="@+id/imageView1"
     android:layout_width="wrap_content"
     android:layout_height="wrap_content"
     android:layout_alignRight="@+id/textView1"
     android:layout_below="@+id/imageView2"
     android:scaleX="1.5"
     android:scaleY="1.5"
     android:src="@drawable/igs_login" />

 <ImageView
     android:id="@+id/imageView2"
     android:layout_width="wrap_content"
     android:layout_height="wrap_content"
     android:layout_alignParentTop="true"
     android:layout_marginTop="21dp"
     android:layout_toRightOf="@+id/button1"
     android:src="@drawable/igs" />

4

2 回答 2

0

错误说得很清楚ScrollView can host only one direct child。这意味着当您使用时,ScrollView您应该考虑创建一个包含所有视图的布局,并将您的视图添加ScrollView为它的父级。例如 :

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

<RelativeLayout
    android:layout_width="match_parent"
    android:layout_height="match_parent" >

    //ADD YOUR VIEWS ONLY HERE

</RelativeLayout>
</ScrollView>

你的布局应该是这样的!而不是RelativeLayout,您可以在任何时候使用您想要的布局,但请记住:All views should be added in one layout

于 2013-07-18T08:17:40.950 回答
0

ScrollView 只能承载一个子项,例如 RelativeLayout 或 LinearLayout(或任何其他扩展 VIewGroup 的 View,因此您的实现应该是这样的:

<ScrollView>
<LinearLayout>

   here you can put how many Views you need 


</LinearLayout>
</ScrollView>
于 2013-07-18T08:20:39.820 回答