1

基本的に、私は一般的な戦術を使用して、 の背景画像を でLinearLayoutラップし、 の前にFrameLayout使用する ImageView を追加することで の中央に配置しています。しかし、ゲームに を追加すると、すべてが変わります。fill_parentLinearLayoutScrollView

問題は、画像が垂直方向に非常に大きく、高さ属性によりとScrollViewの両方の高さが尊重されることです。これにより、イメージが LinearLayout よりも垂直方向に大きい場合に、LinearLayout の下に不要な空白が生じます。ImageViewLinearLayoutwrap_content

FrameLayoutの高さを子 LinearLayout の高さまで伸ばすにはどうすればよいですか? 可能であれば、実行時/描画時にプログラムでサイズを変更することなく。

<ScrollView
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:fillViewport="true" >

    <FrameLayout
        android:layout_width="fill_parent"
        android:layout_height="wrap_content" >

        <ImageView
            android:layout_width="fill_parent"
            android:layout_height="fill_parent"
            android:scaleType="center"
            android:src="@drawable/cash_bg" />

        <LinearLayout
            android:id="@+id/main_ll"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:gravity="center"
            android:orientation="vertical" >

            <!-- My main views are here -->

        </LinearLayout>
    </FrameLayout>
</ScrollView>
4

1 に答える 1

4

私は同じ問題を抱えていて、答えを探していました。これはAndroidのバグだと思います。私が行ったことは、FrameLayoutをLinearLayoutに含めて、FrameLayoutの高さに「fill_parent」を強制できるようにすることです。これにより、複雑さが増しますが、問題は解決します。他の(より良い)解決策は見つかりませんでした。これを試して:

<ScrollView
  android:layout_width="fill_parent"
  android:layout_height="fill_parent"
  android:fillViewport="true" >
  <LinearLayout
   android:layout_width="fill_parent"
   android:layout_height="wrap_content">
    <FrameLayout
        android:layout_width="fill_parent"
        android:layout_height="fill_parent" >

        <ImageView
            android:layout_width="fill_parent"
            android:layout_height="fill_parent"
            android:scaleType="center"
            android:src="@drawable/cash_bg" />

        <LinearLayout
            android:id="@+id/main_ll"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:gravity="center"
            android:orientation="vertical" >

            <!-- My main views are here -->

        </LinearLayout>
    </FrameLayout>
   </LinearLayout>
</ScrollView>
于 2012-09-27T10:19:31.620 に答える