2014-02-20 3 views
2

В моем приложении, я пытался сделать диалог на заказ, так что я написал XML для этого, и в моем XML его появления, как это,пользовательский диалог не идет правильно

enter image description here

dialog.xml,

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
      xmlns:tools="http://schemas.android.com/tools" 
      android:layout_width="fill_parent" 
      android:layout_height="wrap_content" 
      android:orientation="vertical" 
      > 

<RelativeLayout android:layout_width="fill_parent" 
       android:layout_height="50.0dip" 
       android:layout_marginTop="5.0dip" 
       android:layout_margin="5.0dip"> 

    <TextView android:id="@+id/textViewOTPDialogMessage" android:text="@string/OTPDialogActivityMessage" android:gravity="center" android:textStyle="bold" android:textColor="#ff4d4d4d" 
     android:layout_width="wrap_content" android:textSize="18dp" 
     android:layout_height="wrap_content" 
     android:layout_centerVertical="true" /> 

    <View android:layout_marginTop="1.0dip" android:layout_below="@+id/textViewOTPDialogMessage" android:layout_width="fill_parent" android:layout_height="1dp" android:background="@android:color/darker_gray"/> 

</RelativeLayout> 


<RelativeLayout android:layout_width="fill_parent" android:layout_height="50.0dip" android:layout_marginTop="5.0dip"> 

    <TextView android:text="E-Mail Id OTP* " android:id="@+id/textViewEmailOTP" android:textStyle="bold" android:textColor="#ff4d4d4d" 
     android:gravity="left" android:layout_width="wrap_content" 
     android:layout_height="wrap_content" android:layout_marginLeft="10.0dip" android:layout_alignParentLeft="true" 
     android:layout_centerVertical="true" /> 

    <EditText 
     android:id="@+id/editTextEmailIdOtp" android:background="@drawable/custom_edittext" 
     android:paddingLeft="5.0dip" android:layout_width="fill_parent" android:layout_height="35.0dip" 
     android:layout_marginLeft="150.0dip" android:layout_marginRight="10.0dip" 
     android:singleLine="true" android:layout_alignParentLeft="true" 
     android:layout_centerVertical="true" android:imeOptions="actionNext" /> 

</RelativeLayout> 

<RelativeLayout android:layout_width="fill_parent" android:layout_height="50.0dip"> 

    <TextView android:text="Mobile OTP* " android:id="@+id/textViewMobileOTP" android:textStyle="bold" android:textColor="#ff4d4d4d" 
     android:gravity="left" android:layout_width="wrap_content" 
     android:layout_height="wrap_content" android:layout_marginLeft="10.0dip" android:layout_alignParentLeft="true" 
     android:layout_centerVertical="true" /> 

    <EditText 
     android:id="@+id/editTextMobileOtp" android:background="@drawable/custom_edittext" 
     android:paddingLeft="5.0dip" android:layout_width="fill_parent" android:layout_height="35.0dip" 
     android:layout_marginLeft="150.0dip" android:layout_marginRight="10.0dip" 
     android:singleLine="true" android:layout_alignParentLeft="true" 
     android:layout_centerVertical="true" android:imeOptions="actionNext" /> 

</RelativeLayout> 


<Button android:id="@+id/btnValidate" android:text="Validate" android:textSize="18.0sp" android:textStyle="bold" android:textColor="#ff4d4d4d" 
    android:layout_gravity="center_horizontal" android:layout_width="wrap_content" 
    android:layout_height="wrap_content" android:layout_marginTop="10.0dip" android:layout_marginBottom="10.0dip" /> 


</LinearLayout> 

и когда я бегу на моем устройстве тогда,

его приход, как это,

enter image description here

Я попытался увеличить ширину размер не диалог программно, но получить никакой разницы,

private void callOTPDialog() 
    { 
    Dialog myDialog = new Dialog(this); 
    myDialog.requestWindowFeature(Window.FEATURE_NO_TITLE); 
    myDialog.getWindow().setLayout(600, 400); 
    myDialog.setContentView(R.layout.otpdialog); 
    myDialog.setCancelable(false); 
    Button btnValidate = (Button) myDialog.findViewById(R.id.btnValidate); 

    EditText email = (EditText) myDialog.findViewById(R.id.editTextEmailIdOtp); 
    EditText mobile = (EditText) myDialog.findViewById(R.id.editTextMobileOtp); 
    myDialog.show(); 

    btnValidate.setOnClickListener(new OnClickListener() 
    { 

     @Override 
     public void onClick(View v) 
     { 
       //your login calculation goes here 
     } 
    }); 


} 

В XML я упомянул эти строки,

android:layout_width="fill_parent" 
android:layout_height="wrap_content" 

тогда и не знаю, что происходит здесь.

Что теперь делать,

Пожалуйста, помогите,

Спасибо.

+0

опубликовать свое расположение –

+0

@MD: Сообщение пожалуйста см – Android

+0

также опубликовать код pplz .... –

ответ

1

Try, как показано ниже:

LayoutInflater factory = LayoutInflater.from(Splash.this); 

View DialogView = factory.inflate(
      R.layout.custom_progress_layout, null); 

Dialog main_dialog = new Dialog(Splash.this,R.style.Theme_Dialog); 
main_dialog.setContentView(DialogView); 
main_dialog.show(); 

И создать Theme_Dialog в values\styles.xml

<style name="Theme_Dialog" parent="android:Theme.Holo.Dialog"> 
    <item name="android:backgroundDimEnabled">false</item> 
    <item name="android:layout_width">fill_parent</item> 
    <item name="android:windowNoTitle">true</item> 
    <item name="android:windowBackground">@android:color/transparent</item> 
</style> 

Это идеальный вариант, работающий в моем случае.

Update: вам просто нужно изменить и ширину вашего RelativeLayout атрибута с android:layout_width="wrap_content" в вашем layout.xml.

0

добавьте следующую строку в коде:

myDialog.setWindowLayoutMode(FrameLayout.LayoutParams.MATCH_PARENT, FrameLayout.LayoutParams.WRAP_CONTENT); 
1
final Dialog dialog = new Dialog(mContext); 
    dialog.requestWindowFeature((int) Window.FEATURE_NO_TITLE); 
    dialog.setContentView(R.layout.your_layout_here); 
    WindowManager.LayoutParams lp = new WindowManager.LayoutParams(); 
    lp.copyFrom(dialog.getWindow().getAttributes()); 
    lp.width = WindowManager.LayoutParams.WRAP_CONTENT; 
    lp.height = WindowManager.LayoutParams.WRAP_CONTENT; 
    dialog.getWindow().setAttributes(lp); 

Попробуйте один

0

я нашел такую ​​же проблему раньше, и я попытался исправить эту

@Override 
public void onStart() { 
    super.onStart(); 
    LayoutParams params = getDialog().getWindow().getAttributes(); 
    params.width = LayoutParams.MATCH_PARENT; 
    getDialog().getWindow().setAttributes(params);  
} 

надеюсь, что это помогает

0

поместить этот код в OnCreate вашей Dialogue

getWindow().setLayout(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT); 
Смежные вопросы