Android 自定义警报对话框大小被忽略
我有一个自定义的Android 自定义警报对话框大小被忽略,android,android-fragments,android-alertdialog,Android,Android Fragments,Android Alertdialog,我有一个自定义的alertdialog它是250dp乘以300dp,但是当它被渲染时,尺寸基本上变成了match\u parent。据我所知,这可能是由于将null传递给LayoutInflater.inflate(),但我是从片段(特别是在异步任务的onPostExecute()中)而不是适配器生成此自定义对话框的,因此,我不确定如何获得对父视图组的引用 layout.xml: <?xml version="1.0" encoding="utf-8"?> <RelativeL
alertdialog
它是250dp乘以300dp,但是当它被渲染时,尺寸基本上变成了match\u parent
。据我所知,这可能是由于将null
传递给LayoutInflater.inflate()
,但我是从片段
(特别是在异步任务的onPostExecute()
中)而不是适配器
生成此自定义对话框的,因此,我不确定如何获得对父视图组的引用
layout.xml:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="300dp" android:layout_height="250dp"
android:background="@drawable/ad_dialog_background">
<Button
android:layout_width="200dp"
android:layout_height="30dp"
android:text="dismiss"
android:id="@+id/dismissButton_ad"
android:background="@drawable/border"
android:layout_alignParentBottom="true"
android:layout_centerHorizontal="true"
android:layout_marginBottom="10dp"
android:textColor="#484848" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/dialogTitle_ad"
android:textSize="20dp"
android:textColor="#000000"
android:layout_alignParentTop="true"
android:layout_centerHorizontal="true"
android:layout_marginTop="16dp"
android:text="Quote Request Successful" />
<TextView
android:layout_width="180dp"
android:layout_height="148dp"
android:text="Company XYZ:\n\nhas a special on X items from thus and thus a date to thus and thus a date"
android:id="@+id/text_ad"
android:textColor="#000000"
android:layout_below="@+id/dialogTitle_ad"
android:layout_toLeftOf="@+id/actionButtonOne_ad"
android:layout_toStartOf="@+id/actionButtonOne_ad"
android:layout_marginTop="10dp" />
<Button
android:layout_width="90dp"
android:layout_height="30dp"
android:id="@+id/actionButtonOne_ad"
android:background="@drawable/round_corners_list"
android:textColor="#f7f7f7"
android:layout_above="@+id/actionButtonTwo_ad"
android:layout_alignLeft="@+id/actionButtonTwo_ad"
android:layout_alignStart="@+id/actionButtonTwo_ad"
android:layout_marginBottom="10dp"
android:layout_marginRight="3dp"
android:textSize="11dp"
android:text="dssd" />
<Button
android:layout_width="90dp"
android:layout_height="30dp"
android:id="@+id/actionButtonTwo_ad"
android:background="@drawable/round_corners_list"
android:textColor="#f7f7f7"
android:layout_centerVertical="true"
android:layout_alignParentRight="true"
android:layout_alignParentEnd="true"
android:layout_marginRight="3dp"
android:textSize="11dp" />
<Button
android:layout_width="90dp"
android:layout_height="30dp"
android:id="@+id/actionButtonThree_ad"
android:background="@drawable/round_corners_list"
android:textColor="#f7f7f7"
android:layout_below="@+id/actionButtonTwo_ad"
android:layout_alignParentRight="true"
android:layout_alignParentEnd="true"
android:layout_marginTop="10dp"
android:layout_marginRight="3dp"
android:textSize="11dp" />
LayoutInflater inflater = LayoutInflater.from(getActivity());
View view = inflater.inflate(R.layout.ad_dialog, null);
AlertDialog.Builder builder = new AlertDialog.Builder(getActivity());
builder.setView(view);
final AlertDialog dialog = builder.create();
//findViewsById()...
dialog.show();
我的错误是使用了警报对话框
而不是对话框
,并在对话框
对象上调用setContentView(R.layout.myview)
。您在哪里测试它?i、 e emulator上的哪个设备?@ShobhitPuri,在一个设备上我问哪个设备是因为如果它是mdpi或ldpi,那么分辨率会很低,并且根据给定布局的do大小,它可能会占据整个宽度。什么型号?@ShobhitPuri三星s4,你有什么建议?更换测量单位?增大尺寸?如果您看到,设备屏幕的宽度为391dp
,您指定的宽度为300dp
。你的对话框是全屏的吗?试着减小宽度,看看会发生什么。