gpt4 book ai didi

android - 如何将对话框窗口包装到内容中?

转载 作者:搜寻专家 更新时间:2023-11-01 08:48:31 26 4
gpt4 key购买 nike

我正在开发一个对话框,它应该缩小到它的内容,所以,我想在普通 View 中获得类似 wrap_content 的行为,但对于普通的 Dialog .这就是我想在对话框窗口中显示的内容

Layout

在对话窗口中应该是这样的 Desired behaviour

但这是我实际得到的 got behaviour

你能告诉我我做错了什么吗?

在此先感谢您。

这是我的代码

...
final Dialog dialog = new Dialog(this);
dialog.requestWindowFeature(Window.FEATURE_NO_TITLE);
dialog.setContentView(R.layout.advanced_options);
dialog.setTitle(titleId);

// Stuff referred to builder
AlertDialog.Builder builder ...
...

int type = WindowManager.LayoutParams.TYPE_INPUT_METHOD;
WindowManager.LayoutParams w_layout_params = new WindowManager.LayoutParams(type);

dialog.getWindow().setAttributes(w_layout_params );
...
builder.create();
dialog.show();

advanced_options.xml 布局

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/relLayout_advancedOptions"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="vertical"
android:background="@drawable/border_advanced_options"
android:divider="?android:listSeparatorTextViewStyle"
android:showDividers="" >

<TextView
android:id="@+id/speed_limit"
style="?android:attr/listSeparatorTextViewStyle"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentTop="true"
android:layout_marginTop="20dp"
android:text="@string/speed_limit"
android:textAppearance="?android:attr/textAppearanceLarge"
android:textColor="@color/black"
android:textSize="14dp" />

<TextView
android:id="@+id/speed_limit_alert"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_below="@+id/speed_limit"
android:layout_marginLeft="15dp"
android:layout_marginTop="20dp"
android:text="@string/speed_limit_alert"
android:textAppearance="?android:attr/textAppearanceSmall"
android:textColor="@color/black" />


<TextView
android:id="@+id/percent"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignBottom="@+id/speed_limit_alert"
android:layout_toRightOf="@+id/speed_limit_alert_edit_text"
android:text="@string/percentage_symbol"
android:textColor="@color/black" />

<TextView
android:id="@+id/minimum_speed"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignLeft="@+id/speed_limit_alert"
android:layout_below="@+id/speed_limit_alert_edit_text"
android:layout_marginTop="15dp"
android:text="@string/minimum_speed"
android:textAppearance="?android:attr/textAppearanceSmall"
android:textColor="@color/black" />

<EditText
android:id="@+id/minimum_speed_edit_text"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignBaseline="@+id/minimum_speed"
android:layout_alignBottom="@+id/minimum_speed"
android:layout_alignLeft="@+id/speed_limit_alert_edit_text"
android:ems="3"
android:inputType="number"
android:textColor="@color/black"
android:text="6" />

<TextView
android:id="@+id/minimum_speed_unit"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignBottom="@+id/minimum_speed"
android:layout_alignLeft="@+id/percent"
android:text="@string/metric_speed_unit"
android:textAppearance="?android:attr/textAppearanceSmall"
android:textColor="@color/black" />

<TextView
android:id="@+id/maximum_speed"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignLeft="@+id/minimum_speed"
android:layout_below="@+id/minimum_speed_edit_text"
android:layout_marginTop="15dp"
android:text="@string/maximum_speed"
android:textAppearance="?android:attr/textAppearanceSmall"
android:textColor="@color/black"/>

<EditText
android:id="@+id/maximum_speed_edit_text"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignBaseline="@+id/maximum_speed"
android:layout_alignBottom="@+id/maximum_speed"
android:layout_alignLeft="@+id/minimum_speed_edit_text"
android:ems="3"
android:inputType="number"
android:textColor="@color/black"
android:text="18" />

<TextView
android:id="@+id/maximum_speed_unit"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignBottom="@+id/maximum_speed"
android:layout_toRightOf="@+id/maximum_speed_edit_text"
android:text="@string/metric_speed_unit"
android:textAppearance="?android:attr/textAppearanceSmall"
android:textColor="@color/black"/>

<TextView
android:id="@+id/mobile_device_performance"
style="?android:attr/listSeparatorTextViewStyle"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_below="@+id/maximum_speed_edit_text"
android:layout_marginTop="20dp"
android:gravity="center_vertical"
android:text="@string/mobile_device_performance"
android:textAppearance="?android:attr/textAppearanceLarge"
android:textColor="@color/black"
android:textSize="14dp"
android:textStyle="bold" />

<TextView
android:id="@+id/maximum_number_objects"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignLeft="@+id/maximum_speed"
android:layout_below="@+id/mobile_device_performance"
android:layout_marginTop="20dp"
android:text="@string/maximum_objects_in_view"
android:textAppearance="?android:attr/textAppearanceSmall"
android:textColor="@color/black" />

<EditText
android:id="@+id/maximum_number_objects_edit_text"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignBaseline="@+id/maximum_number_objects"
android:layout_alignBottom="@+id/maximum_number_objects"
android:layout_marginLeft="10dp"
android:layout_toRightOf="@+id/maximum_number_objects"
android:ems="3"
android:inputType="number"
android:text="450"
android:textColor="@color/black" />

<EditText
android:id="@+id/speed_limit_alert_edit_text"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignBaseline="@+id/percent"
android:layout_alignBottom="@+id/percent"
android:layout_alignLeft="@+id/maximum_number_objects_edit_text"
android:ems="3"
android:inputType="number"
android:text="42"
android:textColor="@color/black" >

<requestFocus />
</EditText>

<View
android:id="@+id/void_view"
android:layout_width="match_parent"
android:layout_height="20dp"
android:layout_alignParentLeft="true"
android:layout_alignRight="@+id/maximum_speed_unit"
android:layout_below="@+id/maximum_number_objects" />

最佳答案

RelativeView的宽度更改为match_parent

您正在寻找的是 match_parent 的行为。

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/relLayout_advancedOptions"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:background="@drawable/border_advanced_options"
android:divider="?android:listSeparatorTextViewStyle"
android:showDividers="" >

Note: wrap_content in android specifies the view to use as little space as needed and that is the behavior you're getting.

关于android - 如何将对话框窗口包装到内容中?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25876728/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com