0

I'm trying to create RelativeLayout with many widgets and I want to be able to scroll it vertically and horizontally. At first, I made it to scroll only vertically with that xml:

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:fitsSystemWindows="true"
android:orientation="vertical" >

<ScrollView
    android:id="@+id/layoutPostWriteScrollView"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:fillViewport="true" 
    android:fitsSystemWindows="true">

        <RelativeLayout
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:layout_gravity="fill_horizontal"
            android:layout_marginRight="5dp"
            android:fitsSystemWindows="true"
            android:gravity="center" >

            <TextView
                android:id="@+id/layoutPostWriteCtrlLabelTheme"
                style="@style/News.Caption"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:text="Тема" />

            <EditText
                android:id="@+id/layoutPostWriteCtrlTheme"
                android:layout_width="fill_parent"
                android:layout_height="wrap_content"
                android:layout_below="@+id/layoutPostWriteCtrlLabelTheme"
                android:inputType="text" />             

            <LinearLayout
                android:id="@+id/layoutPostWriteEmbeddedMediaLayout"
                android:layout_width="fill_parent"
                android:layout_height="wrap_content"
                android:layout_below="@id/layoutPostWriteCtrlTheme"
                android:gravity="left"
                android:orientation="vertical" />

            <Button
                android:id="@+id/layoutPostWriteAddMediaButton"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_below="@id/layoutPostWriteEmbeddedMediaLayout"
                android:onClick="onAddMediaClick"
                android:text="+ Добавить медиафайл" />

           <TextView
                android:id="@+id/layoutPostWriteCtrlLabelContent"
                style="@style/News.Caption"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_below="@id/layoutPostWriteAddMediaButton"
                android:text="Содержание" />

            <EditText
                android:id="@+id/layoutPostWriteCtrlContent"
                android:layout_width="fill_parent"
                android:layout_height="wrap_content"
                android:layout_below="@id/layoutPostWriteCtrlLabelContent"
                android:gravity="top"
                android:inputType="textMultiLine"
                android:lines="10"
                android:scrollbars="vertical"
                android:singleLine="false" />

            <Button
                android:id="@+id/layoutPostWriteCtrlSave"
                android:layout_width="200dp"
                android:layout_height="40dp"
                android:layout_alignParentRight="true"
                android:layout_below="@id/layoutPostWriteCtrlContent"
                android:background="@drawable/btn_save"
                android:onClick="onClickSendPost" />
        </RelativeLayout>
</ScrollView>

My activity looks like that:

Activity

Everything's allright and that activity scrolls vertically.

But then I tried to add horizontalScrollView like that:

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:fitsSystemWindows="true"
android:orientation="vertical" >

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

    android:fillViewport="true" 
    android:fitsSystemWindows="true">

    <HorizontalScrollView
        android:id="@+id/layoutPostWriteHScrollView"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        android:layout_gravity="fill"
        android:fillViewport="true"
        android:fitsSystemWindows="true" >

        <RelativeLayout
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:layout_gravity="fill_horizontal"
            android:layout_marginRight="5dp"
            android:fitsSystemWindows="true"
            android:gravity="center" >

            <TextView
                android:id="@+id/layoutPostWriteCtrlLabelTheme"
                style="@style/News.Caption"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:text="Тема" />

            <EditText
                android:id="@+id/layoutPostWriteCtrlTheme"
                android:layout_width="fill_parent"
                android:layout_height="wrap_content"
                android:layout_below="@+id/layoutPostWriteCtrlLabelTheme"
                android:inputType="text" />

            <LinearLayout
                android:id="@+id/layoutPostWriteEmbeddedMediaLayout"
                android:layout_width="fill_parent"
                android:layout_height="wrap_content"
                android:layout_below="@id/layoutPostWriteCtrlTheme"
                android:gravity="left"
                android:orientation="vertical" />

            <Button
                android:id="@+id/layoutPostWriteAddMediaButton"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_below="@id/layoutPostWriteEmbeddedMediaLayout"
                android:onClick="onAddMediaClick"
                android:text="+ Добавить медиафайл" />


            <TextView
                android:id="@+id/layoutPostWriteCtrlLabelContent"
                style="@style/News.Caption"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_below="@id/layoutPostWriteAddMediaButton"
                android:text="Содержание" />

            <EditText
                android:id="@+id/layoutPostWriteCtrlContent"
                android:layout_width="fill_parent"
                android:layout_height="wrap_content"
                android:layout_below="@id/layoutPostWriteCtrlLabelContent"
                android:gravity="top"
                android:inputType="textMultiLine"
                android:lines="10"
                android:scrollbars="vertical"
                android:singleLine="false" />

            <Button
                android:id="@+id/layoutPostWriteCtrlSave"
                android:layout_width="200dp"
                android:layout_height="40dp"
                android:layout_alignParentRight="true"
                android:layout_below="@id/layoutPostWriteCtrlContent"
                android:background="@drawable/btn_save"
                android:onClick="onClickSendPost" />
        </RelativeLayout>
    </HorizontalScrollView>
</ScrollView>

There is no errors in markup but activity now looks like that: Activity

All EditTexts and whole RelativeLayout shrinked. How can I make activity to look like at the first image, but scroll vertical and horizontal? I tried many combinations of layout_width and layout_height, but it seems to not work.

1 Answer 1

0

maybe it will helpful for you, there is a Link which describes how to make two dimensional scroll with ScrollView and HorizntalScrollView.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.