RelativeLayout Scrollable

 ̄綄美尐妖づ 提交于 2019-11-29 03:41:50
Jayabal

ScrollView does not allow more than one direct child, that's why you getting error. So you try as follows:

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

<RelativeLayout
  android:layout_width="fill_parent"
  android:layout_height="fill_parent">
         <Button
        android:id="@+id/button1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentRight="true"
        android:layout_alignParentTop="true"
        android:text="Button" />

    <TextView
        android:id="@+id/textView1"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_alignParentLeft="true"
        android:layout_below="@+id/button1"
        android:text="TextView" />

    <TextView
        android:id="@+id/textView2"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_alignParentLeft="true"
        android:layout_below="@+id/textView1"
        android:text="TextView" />

    <TextView
        android:id="@+id/textView3"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_alignParentLeft="true"
        android:layout_below="@+id/textView2"
        android:text="TextView" />

    <Button
        android:id="@+id/button2"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentBottom="true"
        android:layout_centerHorizontal="true"
        android:layout_below="@+id/textView3"
        android:text="Button" />

     </RelativeLayout>
</ScrollView>

You cant put more than one widget in a scrollview. To this you have to wrap your widget with a view. like below

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

    <RelativeLayout
        android:layout_width="fill_parent"
        android:layout_height="fill_parent" >
        <Button
            android:id="@+id/btnBrowser"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_centerVertical="false"
            android:layout_marginTop="5dp"
            android:text="Browser" >

        </Button>


        <TextView
            android:id="@+id/txtAuthor"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_below="@+id/btnBrowser"
            android:layout_marginLeft="20dp"
            android:layout_marginTop="10dp"
            android:text="Text"
            android:textColor="#143781"
            android:textSize="20dp"
            android:textStyle="bold" >
        </TextView>

        <TextView
            android:id="@+id/txtDate"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_below="@+id/txtAuthor"
            android:layout_marginLeft="20dp"
            android:layout_marginTop="5dp"
            android:textColor="#8D89B3"
            android:textSize="14dp" android:text="Text"
            >
        </TextView>

        <TextView
            android:id="@+id/txtTitle"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_below="@+id/txtDate"
            android:layout_marginLeft="20dp"
            android:layout_marginTop="5dp"
            android:textColor="#000000"
            android:textSize="14dp"
            android:textStyle="bold" android:text="Text">
        </TextView>

        <TextView
            android:id="@+id/txtMsg"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_below="@+id/txtTitle"
            android:layout_marginLeft="20dp"
            android:textColor="#000000"
            android:textSize="14dp" android:text="Text">
        </TextView>

        <Button
            android:id="@+id/btnReply"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_below="@+id/txtMsg"
            android:layout_centerInParent="@+id/txtMsg"
            android:layout_marginTop="20dp"
            android:text="Reply" >
        </Button>
    </RelativeLayout>
</ScrollView>

You are adding scrollview inside relativelayout. You have to add Relativelayout inside scrollview to get results. and one more thing scrollview can contains only one child at a time so add relativelayout into scrollview and see the difference

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!