[英]Custom Alert Dialog not resizing
我通過擴展Activity
創建了一個“自定義警報對話框”,並在此活動的onCreate()
方法內部創建了AlertDialog.Builder
對象。
我正在加載我的自定義視圖,但是由於某些原因,無論我是否進行更改,UI中的對話框都保持相同的大小。
首先,我將layout_width
更改為fill_parent
但什么也沒有。 然后我輸入了一些絕對值,例如300dp
但仍然沒有。 這是我的應用程序的sw360dp
布局,在此分辨率下顯示效果不佳,這就是為什么我要對其進行編輯。
我還在此活動中使用Theme.Translucent
,以使其看起來像一個對話框。
下面是對話框窗口的布局以及UI的打印屏幕。您可以看到布局加載直到創建帳戶按鈕。 其他文本視圖不適合。
這是屏幕截圖
任何想法如何解決這一問題?
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/dialog_layout_root"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="@color/light_gray">
<Button
android:id="@+id/facebook_login_button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:layout_marginTop="10dp"/>
<TextView
android:id="@+id/or_text"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textIsSelectable="true"
android:layout_centerHorizontal="true"
android:layout_marginTop="5dp"
android:textSize="12sp"
android:textColor="@color/black"
android:layout_below="@id/facebook_login_button"/>
<TextView
android:id="@+id/sign_in_text"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textIsSelectable="true"
android:layout_marginLeft="5dp"
android:layout_marginTop="5dp"
android:textSize="16sp"
android:textColor="@color/gray"
android:layout_below="@id/or_text"/>
<EditText
android:id="@+id/login_email"
android:layout_width="210dp"
android:layout_height="wrap_content"
android:layout_marginLeft="5dp"
android:layout_below="@id/sign_in_text"
android:hint="@string/email_login"
android:inputType="textEmailAddress"/>
<EditText
android:id="@+id/login_password"
android:layout_width="210dp"
android:layout_height="wrap_content"
android:layout_marginLeft="5dp"
android:layout_below="@id/login_email"
android:hint="@string/pass_login"
android:inputType="textPassword"/>
<TextView
android:id="@+id/case_sensitive_text"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textIsSelectable="true"
android:layout_marginLeft="5dp"
android:layout_marginTop="5dp"
android:textSize="14sp"
android:textColor="@color/gray"
android:layout_below="@id/login_password"/>
<CheckBox
android:id="@+id/remember_login"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textColor="@color/black"
android:layout_below="@id/case_sensitive_text"/>
<Button
android:id="@+id/sign_in_button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@id/remember_login"
android:layout_marginLeft="210dp"/>
<TextView
android:id="@+id/forget_password_text"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textIsSelectable="true"
android:layout_marginLeft="150dp"
android:textSize="15sp"
android:textColor="@color/black"
android:layout_below="@id/sign_in_button"/>
<View
android:id="@+id/horizontal_line"
android:layout_width="360dp"
android:layout_marginTop="20dp"
android:layout_height="1dp"
android:background="@android:color/darker_gray"
android:layout_below="@id/forget_password_text"/>
<TextView
android:id="@+id/new_mav_text"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textIsSelectable="true"
android:textSize="18sp"
android:textColor="@color/black"
android:layout_below="@id/horizontal_line"/>
<TextView
android:id="@+id/create_account_text"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textIsSelectable="true"
android:textSize="18sp"
android:textColor="@color/gray"
android:layout_below="@id/new_mav_text"/>
<Button
android:id="@+id/create_account_button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@id/create_account_text"
android:layout_marginLeft="250dp"
android:layout_marginTop="10dp"/>
<TextView
android:id="@+id/terms_conditions_text"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textIsSelectable="true"
android:textSize="12sp"
android:textColor="@color/gray"
android:layout_below="@id/create_account_button"/>
<TextView
android:id="@+id/vertical_rule"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textIsSelectable="true"
android:textSize="12sp"
android:textColor="@color/gray"
android:layout_below="@id/create_account_button"
android:layout_toRightOf="@id/terms_conditions_text"/>
<TextView
android:id="@+id/privacy_policy_text"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textIsSelectable="true"
android:textSize="12sp"
android:textColor="@color/gray"
android:layout_below="@id/create_account_button"
android:layout_toRightOf="@id/vertical_rule"/>
</RelativeLayout>
您不應該將父布局更改為:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/dialog_layout_root"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
...
嘗試寫是否有效
編輯
您正在嘗試縮小此對話框? 所以我認為問題出在這里:
<View
android:id="@+id/horizontal_line"
android:layout_width="360dp"
android:layout_marginTop="20dp"
android:layout_height="1dp"
android:background="@android:color/darker_gray"
android:layout_below="@id/forget_password_text"/>
並在其他類似的觀點。 您將寬度設置為360dp(這是布局中的最大寬度),以便父級可以適應它。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.