Note that there are some explanatory texts on larger screens.

plurals
  1. POScrollView can host only one direct child exception
    text
    copied!<p>I want to add images to scrollview, there is code i tried to use:</p> <pre><code> 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 ); </code></pre> <p>I get this exception: java.lang.IllegalStateException: ScrollView can host only one direct child</p> <p>So how i should add images to my scrollview ? </p> <p><strong>Added code:</strong> xml:</p> <pre><code>&lt;?xml version="1.0" encoding="utf-8"?&gt; &lt;RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="fill_parent" android:layout_height="fill_parent" android:orientation="vertical"&gt; &lt;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" &gt; &lt;LinearLayout android:layout_width="match_parent" android:layout_height="match_parent" &gt; &lt;/LinearLayout&gt; &lt;/ScrollView&gt; &lt;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" &gt; &lt;LinearLayout android:id="@+id/filesScrollerLayout" android:layout_width="match_parent" android:layout_height="match_parent" &gt; &lt;/LinearLayout&gt; &lt;/ScrollView&gt; &lt;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" /&gt; &lt;/RelativeLayout&gt; </code></pre> <p>And on the end Activity onCreate calling this method:</p> <p>public void addImage(String path){</p> <pre><code> 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 ); } </code></pre> <p>Thanks.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload