2016-01-22 40 views
2

我alertDialog不換行的內容,我嘗試了很多解決方案,但沒有工作,我改變了風格,用對話和... 我想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屬性match_item以及 – drWisdom

+1

謝謝你,這就是答案 – Mohammad

+0

高興它幫助。我發佈這個答案,接受它作爲答案,以便它對別人有幫助。 – drWisdom

回答

2

Android中的對話框通常需要具有最小寬度視圖的寬度。將Spinner的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>