2016-01-22 4 views
2

My alertDialog не переносит его содержимое, я пытаюсь найти множество решений, но не работал. Я изменил стиль, использовал Dialog и ... Я хочу, чтобы AlertDialog обертывал его содержимое.AlertDialog Не обертывает содержимое

Я получаю

enter image description here

, но я хочу это

enter image description here

пользовательский макет:

<?xml version="1.0" encoding="utf-8"?> 
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
       android:id="@+id/settings_ll" 
       android:orientation="vertical" 
       android:layout_width="wrap_content" 
       android:layout_height="wrap_content" 
       android:gravity="right" 
       android:padding="5dp" 
       android:layout_margin="10dp" 
    > 
    <TextView 
     android:id="@+id/font_selection" 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:text="انتخاب قلم:" 
     android:textColor="#000000" 
     android:padding="10dp" 
     android:background="#eeeeee"/> 
    <Spinner 
     android:id="@+id/font_selection_spinner" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:spinnerMode="dropdown" 
     /> 
    <TextView 
     android:id="@+id/size_selection" 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:text="اندازه قلم" 
     android:textColor="#000000" 
     android:padding="10dp" 
     android:background="#eeeeee"/> 
    <LinearLayout 
     android:id="@+id/select_font_size_ll" 
     android:orientation="horizontal" 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:gravity="center"> 
     <Button 
      android:id="@+id/settings_small_btn" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:text="ریز"/> 
     <Button 
      android:id="@+id/settings_normal_btn" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:text="معمولی"/> 
     <Button 
      android:id="@+id/settings_big_btn" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:text="درشت"/> 
    </LinearLayout> 
    <TextView 
     android:id="@+id/sample_tv" 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:textColor="#000000" 
     android:layout_gravity="center" 
     android:gravity="center" 
     android:text="این یک جمبه ی نمونه است" 
     /> 


AlertDialog.java:

public class SettingsDialog extends DialogFragment { 

    @Override 
    public Dialog onCreateDialog(Bundle savedInstanceState) { 

     AlertDialog.Builder builder = new AlertDialog.Builder(getActivity()); 
     // Get the layout inflater 
     LayoutInflater inflater = getActivity().getLayoutInflater(); 

     // Inflate and set the layout for the dialog 
     // Pass null as the parent view because its going in the dialog layout 
     View view = inflater.inflate(R.layout.settings_layout, null); 
     builder.setView(view); 

     return builder.create(); 
    } 
} 
+1

Попробуйте установить layout_width атрибут Spinner элемента к match_item а – drWisdom

+1

спасибо, это ответ – Mohammad

+0

Рад, что помог. Я отправляю это как ответ, принимаю его как ответ, чтобы он помогал другим. – drWisdom

ответ

2

В андроида диалоге обычно имеет ширину зрения с наименьшей шириной. Установите атрибут Spinner's layout_width на match_parent, и вы получите желаемый результат.

+0

Очень полезный совет! Многие другие ответы по этому вопросу предложили изменить параметры макета окна, которые не работали в моем случае. – mpellegr

0

Установить родительский лайнер высоты макета и ширину match_parent и попробовать:

 ?xml version="1.0" encoding="utf-8"?> 
      <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
       android:id="@+id/settings_ll" 
       android:orientation="vertical" 
       android:layout_width="match_parent" 
       android:layout_height="match_parent" 
+0

не работает брат – Mohammad

0

Вы не можете рассчитывать на наличие match_parent на ребенка, у которого есть wrap_content в качестве ширины. Таким образом, установить главную ширину макета как match_parent Ваш счетчик также должен быть match_parent для ширины проверить мой пример:

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

    <TextView 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:text="Title Text" 
     android:gravity="right" 
     android:textSize="20sp" 
     android:padding="10dp"/> 

    <Spinner 
     android:layout_width="match_parent" 
     android:layout_height="50dp" 
     /> 

    <TextView 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:text="Second Title" 
     android:gravity="right" 
     android:textSize="20sp" 
     android:padding="10dp"/> 

    <LinearLayout 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:orientation="horizontal" 
     android:gravity="center"> 

     <Button 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:text="Button 1"/> 
     <Button 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:text="Button 2"/> 
     <Button 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:text="Button 3"/> 

    </LinearLayout> 

    <TextView 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:textSize="18sp" 
     android:text="Bottom text" 
     android:gravity="center"/> 

</LinearLayout> 
Смежные вопросы