Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7864613
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T23:50:13+00:00 2026-06-02T23:50:13+00:00

I want to add images to scrollview, there is code i tried to use:

  • 0

I want to add images to scrollview, there is code i tried to use:

        ScrollView sv = (ScrollView)findViewById( R.id.scrollView2);
        ImageView iv = new ImageView(this);
        iv.setImageDrawable( new BitmapDrawable( "PATH" ) );
        iv.setScaleType( ScaleType.CENTER_INSIDE );
        sv.addView( sv ); 

I get this exception:
java.lang.IllegalStateException: ScrollView can host only one direct child

So how i should add images to my scrollview ?

Added code:
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="fill_parent"
    android:orientation="vertical">

    <ScrollView
        android:id="@+id/scrollView1"
        android:layout_width="100dp"
        android:layout_height="wrap_content"
        android:layout_alignParentBottom="true"
        android:layout_alignParentLeft="true"
        android:layout_alignParentTop="true"
        android:background="#FF0000" >

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

        </LinearLayout>
    </ScrollView>

    <ScrollView
        android:id="@+id/scrollView2"
        android:layout_width="200dp"
        android:layout_height="wrap_content"
        android:layout_alignParentBottom="true"
        android:layout_alignParentTop="true"
        android:layout_toRightOf="@+id/scrollView1"
        android:background="#FFFF00" >

        <LinearLayout
            android:id="@+id/filesScrollerLayout"
            android:layout_width="match_parent"
            android:layout_height="match_parent" >
        </LinearLayout>
    </ScrollView>

    <ImageView
        android:id="@+id/imageView1"
        android:layout_width="wrap_content"
        android:layout_height="250dp"
        android:layout_alignParentBottom="true"
        android:layout_alignParentRight="true"
        android:background="#FFFFFF"
        android:layout_toRightOf="@+id/scrollView2" />

</RelativeLayout>

And on the end Activity onCreate calling this method:

public void addImage(String path){

            LinearLayout sv = (LinearLayout)findViewById( R.id.filesScrollerLayout);
        ImageView iv = new ImageView(this);
        iv.setImageDrawable( new BitmapDrawable( path ) ); 
        iv.setScaleType( ScaleType.CENTER_INSIDE );
        sv.addView( sv ); 

}

Thanks.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-02T23:50:14+00:00Added an answer on June 2, 2026 at 11:50 pm

    this may help.. it tells so because ScrollView cannot hold more than 1 child.. it needs single child which hosts all other view..

    <ScrollView>
    <LinearLayout
    android:id="@+id/child">
        <ImageView/>
        ...
        ...
    </LinearLayout>
    </ScrollView>
    

    in your case

    LinearLayout child = (LinearLayout)findViewById( R.id.child);
            ImageView iv = new ImageView(this);
            iv.setImageDrawable( new BitmapDrawable( "PATH" ) );
            iv.setScaleType( ScaleType.CENTER_INSIDE );
            child.addView( sv ); 
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

i want to add buttons dynamically along with the scrollview ,suppose there are like
I have this code for a scrollview to showe 3 images: const CGFloat kScrollObjHeight
I want to use camera preview in an activity. I want to add images(transparent
I have created a UIView through code and want to add some images and
i want to add images or labels with image in it to a panel
I want to add images to the items in a list in Eclipse RCP.
I want to know how to add images while exporting the image from highcharts.
I have 3 images that I want to add one after other on a
I've uploaded a bunch of images to Amazon S3, and now want to add
i want to add image inside a span here's what i tried ( inside

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.