我的警报大小在android中显示不正确?
我的警报宽度太短 截图: 以下是设计xml:我的警报大小在android中显示不正确?,android,Android,我的警报宽度太短 截图: 以下是设计xml: <?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="match_parent"> <LinearLayout android
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent">
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="match_parent"
android:layout_gravity="center"
android:orientation="vertical">
<android.support.v7.widget.AppCompatTextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="20dp"
android:text="@string/name"
/>
<android.support.v7.widget.AppCompatTextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="20dp"
android:layout_marginTop="15dp"
android:text="Hari"
android:textColor="@color/colorPrimaryBlack"
/>
<android.support.v7.widget.AppCompatTextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="20dp"
android:layout_marginTop="15dp"
android:text="@string/customer_id1"
/>
<android.support.v7.widget.AppCompatTextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="20dp"
android:layout_marginTop="15dp"
android:text="96"
android:textColor="@color/colorPrimaryBlack"
/>
<android.support.v7.widget.AppCompatTextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="20dp"
android:layout_marginTop="15dp"
android:text="@string/mobile"
/>
<android.support.v7.widget.AppCompatTextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="20dp"
android:layout_marginTop="15dp"
android:text="7826963223"
android:textColor="@color/colorPrimaryBlack"
/>
<android.support.v7.widget.AppCompatTextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="20dp"
android:layout_marginTop="15dp"
android:text="@string/pickup_address"
/>
<android.support.v7.widget.AppCompatTextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="20dp"
android:layout_marginTop="15dp"
android:text="ponmeni Muniyandi kovil main road"
android:textColor="@color/colorPrimaryBlack"
/>
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:paddingBottom="1.0dip"
android:paddingLeft="4.0dip"
android:paddingRight="4.0dip"
android:layout_marginTop="15dp"
android:paddingTop="5.0dip">
<Button
android:id="@+id/Accept"
android:layout_width="0.0dip"
android:layout_height="fill_parent"
android:layout_marginLeft="15dp"
android:layout_weight="1.0"
android:background="@drawable/btn_rounded_primary"
android:textColor="@color/colorPrimarywhite"
android:text="@string/btn_accept" />
<Button
android:id="@+id/Decline"
android:layout_width="0.0dip"
android:layout_height="fill_parent"
android:layout_marginLeft="10dp"
android:layout_marginRight="15dp"
android:layout_weight="1.0"
android:background="@drawable/btn_rounded_black"
android:text="@string/btn_decline"
android:textColor="@color/colorPrimarywhite" />
</LinearLayout>
</LinearLayout>
</LinearLayout>
您可以通过以下方式控制警报框的大小:
alertDialog.getWindow().setLayout(100, 400); //Controlling width and height.
使用
窗口
Dialog dialog = new Dialog(this);
dialog.setContentView(R.layout.your_layout);
Window window = dialog.getWindow();
window.setLayout(WindowManager.LayoutParams.MATCH_PARENT, WindowManager.LayoutParams.WRAP_CONTENT);
window.setGravity(Gravity.CENTER);
dialog.show();
也可以使用android:layout\u width=“match\u parent”
而不是android:layout\u width=“fill\u parent”
来进行LinearLayout
因为android:layout\u width=“fill\u parent”这个值从API级别8开始就被弃用,取而代之的是MATCH\u parent
您可以尝试以下操作:
dialog.getWindow().setLayout(ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT);
共享警报对话框的代码首先用match_parent替换fill_parent,因为fill_parent已被弃用,并向我展示java代码在何处放大此对话框作为旁注,我认为拒绝按钮应始终位于后退按钮的一侧。还要注意的是,每个设备的情况都有所不同。