電子書籍のように、横軸でスクロールできるアクティビティが 1 つある Android タブレット 3.0 用のアプリケーションを開発しています。
そのために、レイアウトの HorizontalScrollView 内で RelativeLayout を使用しています。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>
この xml ファイルは main.xml と呼ばれます。
私がJavaファイルでやっていることは次のとおりです。
setContentView(R.layout.main);
parent = (ViewGroup) findViewById(R.id.container);
View v = createView(); // Thats working for sure.
parent.addView(v);
ビュー V が画面に表示されません。しかし、私がそうするなら
addContentView(v)
ビュー v を画面に追加します (私の方法が機能することの証明です) が、HorizontalScrollView の外側にあるため、スクロールできません。私は何を間違っていますか?
更新:私はそれを試しましたが、うまくいきませんでした:
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);
青色の背景が得られません。