Note that there are some explanatory texts on larger screens.

plurals
  1. POInsert a view dynamically in a HorizontalScrollView in Android
    primarykey
    data
    text
    <p>I'm developing an application for Android tablet 3.0 that has one activity that should be scrollable in the horizontal axis, like an e-book. </p> <p>For that, I'm using a RelativeLayout inside a HorizontalScrollView on my layout. Here is the XML: </p> <pre><code>&lt;?xml version="1.0" encoding="utf-8"?&gt; &lt;HorizontalScrollView xmlns:android="http://schemas.android.com/apk/res/android" android:orientation="horizontal" android:layout_width="800px" android:id="@+id/horizontalScroll" android:background="#C6D7D2" android:layout_height="600px"&gt; &lt;RelativeLayout android:id="@+id/container" android:layout_width="fill_parent" android:layout_height="fill_parent"&gt; &lt;/RelativeLayout&gt; &lt;/HorizontalScrollView&gt; </code></pre> <p>This xml file is called main.xml.</p> <p>What I'm doing in the java file is:</p> <pre><code>setContentView(R.layout.main); parent = (ViewGroup) findViewById(R.id.container); View v = createView(); // Thats working for sure. parent.addView(v); </code></pre> <p>But it is not working, the view V doesn't show on the screen. But if i do </p> <pre><code>addContentView(v) </code></pre> <p>it adds the view v to the screen (the proof that my method works), but it isn't scrollable since it is outside the HorizontalScrollView. What am I doing wrong?</p> <p>UPDATE: I tried with that and it also didn't work out:</p> <pre><code>setContentView(R.layout.main); LayoutParams params = new LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT); ViewGroup parent = (ViewGroup) findViewById(R.id.container); View v = new View(this); v.setBackgroundColor(Color.BLUE); parent.addView(v,params); </code></pre> <p>I don't get a blue background.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

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