5

私は最近、明らかに単純な Android レイアウトに苦労しましWebViewButton。以下のパラメータで問題なく動作しました。

WebView:
  Height: wrap-content
  Weight: unset (by the way, what is the default?)

Button:
  Height: wrap-content
  Weight: unset

ただし、Web ページが大きくなりすぎると、ボタンからはみ出してしまいます。重みと高さのさまざまな組み合わせを試してみましたが、1 つを除いて、ボタンを完全に隠すか、部分的に覆うかのいずれかでした。これは機能するものです(http://code.google.com/p/apps-for-android/source/browse/trunk/Samples/WebViewDemo/res/layout/main.xmlからコピー):

WebView:
  Height: 0
  Weight: 1

Button:
  Height: wrap-content
  Weight: unset

これらのいずれかを変更すると、たとえばボタンに重みを付けたり、WebView高さをラップコンテンツに変更したりすると、機能しません。私の質問は:なぜですか?誰かがアンドロイドレイアウトシステムが何を考えているのか説明してもらえますか?

4

5 に答える 5

3

次のようなもので、必要なものが得られるはずです。キーは、WebView の layout_height="fill_parent" と layout_weight="1" です。

<LinearLayout android:orientation="vertical"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent">
        <WebView android:layout_width="fill_parent"
            android:layout_height="fill_parent"
            android:layout_weight="1" />

        <Button android:layout_width="fill_parent"
                android:layout_height="wrap_content" />
</LinearLayout>  


編集:おっと、あなたの質問を誤解しました。ボタン(または例ではテキストビュー)にこぼれないようにするのは、layout_weightです。なぜそうなるのかはわかりませんが、LinearLayout に 1 つ以上の「wrap_content」アイテムに加えて「fill_parent」アイテムが 1 つある場合、「fill_parent」アイテムに layout_weight を指定する必要があります。ウィジェットの残りのスペースの上。

于 2010-03-25T22:29:29.767 に答える
-1

webViewの高さをピクセル単位で指定できます

android:layout_heigth = " 70px"

例えば

それが役に立てば幸い

于 2011-03-11T15:24:44.340 に答える
-1

次のようなことを試すことができます:

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
   android:layout_width="fill_parent"
    android:layout_height="match_parent" >

        <WebView
                android:id="@+id/wv"
                android:layout_width="match_parent"
                android:layout_height="match_parent"
                android:layout_above="@+id/btn" />

        <Button
            android:id="@+id/btn"
            android:layout_alignParentBottom="true" />
</RelativeLayout>
于 2012-10-09T12:18:44.740 に答える