2

私は垂直レイアウトを持っています: 2 つのテキスト フィールドとボタンの水平バー:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:background="#ff00ff00"
    android:orientation="vertical"
    android:padding="4dp" >

        <EditText
            android:id="@+id/et_email"
            android:layout_width="fill_parent"
            android:layout_weight="1"
            android:layout_height="wrap_content"
            android:layout_marginTop="2dp"
            android:background="#ff00ffff"
            android:inputType="textEmailAddress" >
        </EditText>

        <EditText
            android:id="@+id/et_comment"
            android:layout_width="fill_parent"
            android:layout_weight="1"
            android:layout_height="wrap_content"
            android:layout_marginTop="2dp"
            android:background="#ff00ffff"
            android:inputType="textMultiLine"
            android:maxLines="5"
            android:minLines="5" />

    <LinearLayout
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:orientation="horizontal" >

        <Button
            android:id="@+id/btn_send"
            android:layout_weight="0"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="OK" />

        <Button
            android:id="@+id/btn_show"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="Some very long text" />

        <Button
            android:id="@+id/btn_cancel"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="Cancel" />
    </LinearLayout>

</LinearLayout>

ボタン バーにサイズ ポリシーを設定したいwrap_content(このアプリにはさまざまなローカライズがあるため、固定サイズにすることさえできません)。また、テキスト フィールドの幅をボタン ボックスと同じにしたいと考えています。プラットフォーム 17 が選択された状態で上記の xml がデザイナー (Eclipse + ADT) でどのように表示されるか (およびどのように表示されるか) を次に示します。色は簡単にデバッグするためのものです:

ここに画像の説明を入力

Android 4.1 タブレットでは次のように表示されます。

ここに画像の説明を入力

このレイアウトは、ダイアログのカスタム レイアウトとして使用されます。コンテンツとタイトルの設定を除いて、Dialog に対して操作は行われていません。

興味深い事実: Android 3.1 タブレットでは、私が望んでいたとおり (および ADT デザイナーが示したものと同じ) に見えます。しかし、4.1ではありません。

目的のレイアウトを実現するにはどうすればよいですか?

4

2 に答える 2

1

これはばかげているようですが、うまくいくようです。ネストされたレイアウトを入れてみてください。外側のレイアウトの幅/高さを変更して、親を埋めます。次に、その中にすべてのビューなどを含む別の線形レイアウトを作成します。内側の LinearLayout に wrap_content 値を指定すると、それが実行されます。これよりも良い方法があるはずですが、現時点では思いつきません。

于 2013-07-11T14:32:46.463 に答える