I am developing an application for Android 3.0, which has one action that should scroll along the horizontal axis, for example, in an e-book.
For this, I use RelativeLayout inside a HorizontalScrollView in my layout. Here is the XML:
<?xml version="1.0" encoding="utf-8"?> <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"> <RelativeLayout android:id="@+id/container" android:layout_width="fill_parent" android:layout_height="fill_parent"> </RelativeLayout> </HorizontalScrollView>
This XML file is called main.xml.
What am I doing in the java file:
setContentView(R.layout.main); parent = (ViewGroup) findViewById(R.id.container); View v = createView();
But it does not work, view V is not displayed on the screen. But if I do
addContentView(v)
it adds the v view to the screen (proof that my method works), but it doesn't scroll as it is outside of the HorizontalScrollView. What am I doing wrong?
UPDATE: I tried with this, and it also failed:
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);
I do not get a blue background.
source share