0

私はアンドロイドを初めて使用します。携帯電話でこのapkファイルを実行すると実行され、水平方向のビューに回転すると、ページの半分しか表示されず、スクロールしようとするとスクロールしません.ScrollViewを使用して多くのことを試しました.実装されていません。発生するエラーは、「activity_main.xml: ScrollView は直接の子を 1 つだけホストできます」です。解決方法を教えてもらえますか??

  <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 に答える