我的警报大小在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: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>
答
试试这套对话框布局HIGHT和宽度编程使用Window
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_width="match_parent"
代替android:layout_width="fill_parent"
您LinearLayout
怎么一回事,因为
android:layout_width="fill_parent"
该值已弃用的API 8级开始,并通过MATCH_PARENT
取代。
答
您可以通过这个控制你的警告框尺寸:
alertDialog.getWindow().setLayout(100, 400); //Controlling width and height.
答
做到这一点,它一定会解决您的问题。
dialog.getWindow().setLayout(ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT);
分享您的警告对话框代码 –
首先是因为FILL_PARENT弃用match_parent更换FILL_PARENT [查看](https://developer.android.com/reference/android/view/ViewGroup.LayoutParams.html#FILL_PARENT)和向我展示java代码,你在这个对话框中充气 – UltimateDevil
作为旁注,我相信下降按钮应该总是在后退按钮的一侧。还要注意,每个设备都有所不同。 – Doomsknight