0

I am trying to put imageview in the scrollview in android studio, but it doesn't lets me drag and drop imageview in the scrollview.

Here's my code:

<?xml version="1.0" encoding="utf-8"?>
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:background="#ccc"
    android:gravity="center"
    android:orientation="vertical"
    android:paddingTop="30dp">

    <LinearLayout
        android:id="@+id/content"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_margin="5dp"
        android:background="#ffffff"
        android:gravity="center"
        android:orientation="vertical"
        android:textColor="#ffffff">

        <TextView
            android:id="@+id/homepagetxt"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_marginBottom="10dp"
            android:layout_marginLeft="10dp"
            android:layout_marginRight="10dp"
            android:layout_marginTop="10dp"
            android:textColor="#000000"
            android:textStyle="italic" />

    </LinearLayout>


</ScrollView>

I can put it in Linear layout, but it messes up the layout of my screen. However, I cant put it up in the scroll view like after the linearlayout closing tag.

Is there any limitation of putting imageview in scrollview?

I'd appreciate your kind response.

CommonsWare
  • 986,068
  • 189
  • 2,389
  • 2,491
Umair K
  • 35
  • 4

2 Answers2

1

Is there any limitation of putting imageview in scrollview?

No. However, a ScrollView can only have one child. At the moment, that is your LinearLayout.

CommonsWare
  • 986,068
  • 189
  • 2,389
  • 2,491
1

A ScrollView can have only one direct child. If you want to put several views in it, you have to put these views in a LinearLayout or RelativeLayout.

Scrollview can host only one direct child

Community
  • 1
  • 1
thib sig
  • 164
  • 9
  • oh.. Is it possible that I can have a linear layout containing another linear layout and a scrollview? – Umair K Apr 11 '16 at 23:57
  • Yes because a Linear (or Relative) Layout can contain several direct childrens but a scroll view can have only one direct child. – thib sig Apr 12 '16 at 00:00