0

以下は、私の Android アプリの xml レイアウトです。画面のグリッドビューの下に Web ビューを配置しようとしています。

それを機能させるために何をする必要があるかを説明してくれる人はいますか?

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/db1_root"
    android:orientation="vertical"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent">
    <LinearLayout
        android:id="@+id/HomePage"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent">
        <GridView
            android:id="@+id/Grid"
            android:layout_width="fill_parent"
            android:layout_height="fill_parent"
            android:columnWidth="90dp"
            android:numColumns="auto_fit"
            android:verticalSpacing="10dp"
            android:horizontalSpacing="10dp"
            android:stretchMode="columnWidth"
            android:gravity="center"
            android:scrollbars="vertical" />
        <WebView
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:id="@+id/webView1" />
    </LinearLayout>
</LinearLayout>

ありがとう

4

2 に答える 2

0

2 つの小さな変更が、この作業を行うのに役立つと思います。まず、LinearLayout を作成するときにandroid:orientation、子を水平方向に追加するか垂直方向に追加するかを示す属性が必要です。あるビューを別のビューの上に重ねたいのでandroid:orientation=vertical、HomePage LinearLayout に追加します。次に、GridView には現在、android:layout_heightof がありfill_parentます。これにより、垂直方向に拡張され、LinearLayout 全体がいっぱいになり、WebView が表示されなくなります。この属性を に変更してみてくださいwrap_content

両方の子の高さを設定wrap_contentすると、アプリに空きスペースが生じる可能性があります。ビュー内のすべての空き領域を占有するために GridView または WebView が必要な場合は、android:layout_weight属性を使用できます。残りの部分が次のように属性を描画された後、残りのすべてのスペースを埋めるために展開するビューを割り当てますandroid:layout_weight=1。(ここでは、1 は残りのスペースの 100% を表します) 子が占める親のパーセンテージをより詳細に制御したい場合は、android:layout_weight属性で 10 進値を使用するか、各子のandroid:weightSuma と組み合わせて親で使用することを検討してください。 android:layout_weight. お役に立てれば!

于 2012-11-28T23:18:24.677 に答える
0

android:layout_height="wrap_content"グリッドビューで使用

内側の線形レイアウトで方向属性を設定します。

android:orientation="vertical"

WebView の高さを固定 android:layout_weight=""し、両方の子に設定します。

以下のコードを試して、Web ビューの高さとグリッド ビューの高さに応じて変更してください。

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/db1_root"
    android:orientation="vertical"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent">
    <LinearLayout
        android:id="@+id/HomePage"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        android:weightSum="2"
        android:orientation="vertical">
        <GridView
            android:id="@+id/Grid"
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:columnWidth="90dp"
            android:numColumns="auto_fit"
            android:verticalSpacing="10dp"
            android:horizontalSpacing="10dp"
            android:stretchMode="columnWidth"
            android:gravity="center"
           android:layout_weight="1"
            android:scrollbars="vertical" />
        <WebView
            android:layout_width="fill_parent"
            android:layout_height="200dp"
            android:layout_weight="1"
            android:id="@+id/webView1"
            />
    </LinearLayout>
</LinearLayout>

上記のコードではWebView 200dp、要件に応じて変更の高さを指定しています。

于 2012-11-29T05:56:13.257 に答える