2013-11-26 4 views
4

У меня есть EditText s внутри макета, который я определил для вида пользовательского DialogFragment. Я положил поля справа от них. Но это не отражает, когда на экране отображается диалоговое окно DialogFragment.Маргинальные атрибуты, не работающие внутри настраиваемого диалогового окна DialogFragment

login_dialog.xml

<?xml version="1.0" encoding="utf-8"?> 
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    android:background="@color/lightBlack" > 

    <Button 
     android:id="@+id/loginDialogCloseButton" 
     android:layout_width="50dp" 
     android:layout_height="50dp" 
     android:background="@drawable/btn_dialog_disable" 
     android:layout_alignParentRight="true" 
     android:layout_alignParentTop="true" 
     android:layout_marginTop="10dp" 
     android:layout_marginRight="20dp" 


     /> 

    <TextView 
     android:id="@+id/loginNameTextView" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:text="NAME" 
     android:layout_alignParentLeft="true" 
     android:layout_marginLeft="10dp" 
     android:layout_alignBottom="@+id/loginNameEditText" 

     android:layout_marginBottom="10dp" 
     android:textStyle="bold" 
     android:textColor="@android:color/darker_gray"   
     /> 

    <EditText 
     android:id="@+id/loginNameEditText" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:layout_alignLeft="@+id/loginPasswordEditText" 
     android:layout_alignParentRight="true" 
     android:layout_marginRight="20dp" 
     android:layout_below="@+id/loginDialogCloseButton" 

     android:layout_marginTop="20dp" 
     android:layout_toRightOf="@+id/loginNameTextView" /> 

    <TextView 
     android:id="@+id/loginPasswordTextView" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:text="PASSWORD" 
     android:layout_alignParentLeft="true" 
     android:layout_marginLeft="10dp" 
     android:layout_alignBottom="@+id/loginPasswordEditText"   
     android:layout_marginBottom="10dp" 
     android:textStyle="bold" 
     android:textColor="@android:color/darker_gray"   
     /> 
    <EditText 
     android:id="@+id/loginPasswordEditText" 
     android:inputType="textPassword" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:layout_below="@+id/loginNameEditText" 
     android:layout_toRightOf="@+id/loginPasswordTextView" 
     android:layout_alignParentRight="true" 
     android:layout_marginRight="20dp" 
     android:layout_marginTop="20dp" 

     android:layout_marginLeft="10dp" 
     /> 

    <Button 
     android:id="@+id/loginButton" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:layout_alignRight="@+id/loginPasswordEditText" 
     android:layout_below="@+id/loginPasswordEditText" 
     android:layout_marginTop="20dp" 
     android:text="LOGIN" 
     android:gravity="center" 
     android:textColor="@color/lightBlack" 
     android:textStyle="bold" /> 

</RelativeLayout> 

LoginDialog.java

@SuppressLint("ValidFragment") 
public class LoginDialog extends DialogFragment { 

    //*******interface for communicating with the host********// 
    public interface LoginCommunicator{ 
     public void getLoginCredentials(String name,String password); 

    } 

    LoginCommunicator listener; 

    //******default constructor*********************// 
    public LoginDialog() { 
     // TODO Auto-generated constructor stub 
    } 

    public LoginDialog(FragmentSettings fragmentSettings) { 
     // TODO Auto-generated constructor stub 
     listener=fragmentSettings; 
    } 

    /*//********from stackOverflow: it's safer to add the request for 
    a title-less window in the onCreateDialog() method instead of 
    onCreateView(). This way you can prevent ennoying NPE when 
    you're not using your fragment as a Dialog 
*/ 
    @Override 
    public Dialog onCreateDialog(Bundle savedInstanceState) { 
     // TODO Auto-generated method stub 
     Dialog dialog= super.onCreateDialog(savedInstanceState); 

     dialog.getWindow().requestFeature(Window.FEATURE_NO_TITLE); 

     return dialog; 
    } 

    @Override 
    public View onCreateView(LayoutInflater inflater, ViewGroup container, 
      Bundle savedInstanceState) { 
     // TODO Auto-generated method stub 
     View view=inflater.inflate(R.layout.login_dialog, container); 
    // getDialog().setTitle("LOGIN"); 

    // getDialog().getWindow().setBackgroundDrawable(new ColorDrawable(android.graphics.Color.TRANSPARENT)); 
     final EditText loginNameEditText=(EditText)view.findViewById(R.id.loginNameEditText); 
     final EditText loginPasswordEditText=(EditText)view.findViewById(R.id.loginPasswordEditText); 

     Button loginButton=(Button) view.findViewById(R.id.loginButton); 
     loginButton.setOnClickListener(new View.OnClickListener() { 

      @Override 
      public void onClick(View arg0) { 
       // TODO Auto-generated method stub 
       String name=loginNameEditText.getText().toString(); 
       String password=loginPasswordEditText.getText().toString(); 

       listener.getLoginCredentials(name, password); 
      } 
     }); 
     return view; 
    } 
} 

Просмотр визуализации:

enter image description here

поэтому android:layout_marginRight="20dp" не осуществляем никаких изменений. Как добиться этого изменения?

ответ

14

В некоторых случаях очень внешний margin просто не работает или обрезается до нуля на некоторых версиях Android API. Это в основном происходит в AdapterView s и Dialog s. Если вы используете padding, он будет работать на всех версиях Android.

+0

Его странное я должен сказать, но его работа с дополнением. Благодарю. –

+0

Извините, мне потребовалось 6 минут. Между тем занят другими вещами. Принято сейчас :) –

 Смежные вопросы

  • Нет связанных вопросов^_^