0

ダイアログの下部にメッセージといくつかのボタンがあるダイアログを表示したい。

ダイアログにさらにコントロールを追加するつもりなので、カスタム ビューを使用します。

コードは次のとおりです。

私のhv_popup.xml

<RelativeLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:layout_alignParentBottom="true"
    android:layout_gravity="bottom"
    android:background="#ffff00">

    <LinearLayout
        android:id="@+id/hvBottomBar"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_alignParentBottom="true"
        android:orientation="horizontal"> 

        <Button
            android:id="@+id/btnSwitch"
            android:layout_weight="1"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:text="MTD/HV" />

        <Button
            android:id="@+id/btnEDIT"
            android:layout_weight="1"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:text="EDIT" />

        <Button
            android:id="@+id/btnCancel"
            android:layout_weight="1"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:text="CLOSE" />

    </LinearLayout>

    <TextView
        android:id="@+id/etHV"
        android:background="#000000"
        android:textColor="#ffffff"
        android:textIsSelectable="true"
        android:textSize="12sp"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_above="@+id/hvBottomBar"/>
</RelativeLayout>

Java コード:

final Dialog dialog = new Dialog(this);
dialog.requestWindowFeature(Window.FEATURE_NO_TITLE);
Window window = dialog.getWindow();
window.setGravity(Gravity.BOTTOM | Gravity.CENTER_HORIZONTAL);
window.setLayout(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT);

dialog.setContentView(R.layout.hv_popup);

final TextView tv = (TextView) dialog.findViewById(R.id.etHV);
tv.setText("text");
dialog.show();

結果:

問題:

  • etHV短いテキストがある場合、ダイアログは画面全体のスペースを占有しますが、コンテンツの高さに折り返すだけです。
  • 長いテキストがあるとetHV、使用可能なスペースがすべて使用され、画面の外にボタンが押し出されます

私の期待される結果:

  • ダイアログは画面の下部に揃えます
  • ダイアログはコンテンツの高さに折り返されます
  • 長いテキストを に設定した場合でも、ボタンは常に表示されている必要がありますetHV
  • 長いテキストがある場合etHV、表示されているダイアログの残りのスペースのみが必要であり、スクロール可能になり、ユーザーにはダイアログの下部にボタンが表示されます。
4

1 に答える 1