![](/img/trans.png)
[英]Prevent dialog from taking up whole width of screen in landscape mode - Android
[英]Dialog is taking the whole screen width
我做了一個自定義對話框
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:orientation="vertical"
android:id="@+id/dialog_root"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingLeft="@dimen/dialog_text_padding"
android:paddingRight="@dimen/dialog_text_padding"
android:paddingTop="@dimen/dialog_text_padding">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/dialog_heading"
tools:text="Permissions"
android:textStyle="bold"
android:textColor="@color/brand_color"
android:textSize="22sp"
/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/dialog_text"
android:clickable="true"
android:layout_marginTop="@dimen/padding_large"
android:textSize="18sp"
tools:text="This app determines your phone location and shares it with Google to server personalized alters for you. This allows for a better app pferformance"/>
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:paddingBottom="24dp"
android:id="@+id/okCancelView"
android:paddingTop="@dimen/dialog_text_padding"
android:paddingLeft="@dimen/dialog_text_padding"
>
<TextView
android:layout_width="wrap_content"
android:layout_toLeftOf="@+id/dialog_cancel"
android:layout_marginRight="@dimen/dialog_text_padding"
android:gravity="center"
android:layout_height="wrap_content"
android:paddingTop="10dp"
android:paddingBottom="10dp"
android:paddingLeft="20dp"
android:paddingRight="20dp"
tools:text="OK"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
tools:text="CANCEL"
android:padding="10dp"
android:layout_alignParentRight="true"
android:textColor="@color/dialog_heading"
android:gravity="center"/>
</RelativeLayout>
</LinearLayout>
我用簡單的方式展示
Dialog d=new Dialog(this);
d.setContentView(R.layout.custom_dialog);
d.show();
但是我的對話框占用了整個屏幕的寬度(已附加圖片)。 為什么屏幕和對話框之間沒有空間?
Display display = ((Activity) ctx).getWindowManager()
.getDefaultDisplay();
Point size = new Point();
display.getSize(size);
int width = size.x;
alert_dialog.getWindow().setLayout((int) (width * .89),
LayoutParams.WRAP_CONTENT);
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.