2016-09-01 15 views
0

私は現在、本から与えられたいくつかのアプリケーションデモを見ています.AlertDialogを利用するこの特定のアプリケーションは、メッセージとレイアウトが重なり、この特定のレイアウトを使用するときにのみ起こるという点で非常に奇妙です。私は同じ結果をエミュレータと実デバイスの両方でアプリを実行しようとしました。この問題を解決するための助けに感謝します! AlertDialog setMessage cut off

ここにダイアログクラスがあります。

package android.bignerdranch.com.notetoself; 

import android.app.AlertDialog; 
import android.app.Dialog; 
import android.app.DialogFragment; 
import android.os.Bundle; 
import android.view.LayoutInflater; 
import android.view.View; 
import android.widget.Button; 
import android.widget.ImageView; 
import android.widget.TextView; 

public class DialogShowNote extends DialogFragment { 

    Note mNote; 

    @Override 
    public Dialog onCreateDialog(Bundle savedInstanceState) { 

     AlertDialog.Builder builder = new AlertDialog.Builder(getActivity()); 

     LayoutInflater inflater = getActivity().getLayoutInflater(); 
     View dialogView = inflater.inflate(R.layout.dialog_show_note, null); 

     TextView txtTitle = (TextView) dialogView.findViewById(R.id.txtTitle); 
     TextView txtDescription = (TextView) dialogView.findViewById(R.id.txtDescription); 
     txtTitle.setText(mNote.getTitle()); 
     txtDescription.setText(mNote.getDescription()); 

     ImageView ivImportant = (ImageView) dialogView.findViewById(R.id.imageViewImportant); 
     ImageView ivTodo = (ImageView) dialogView.findViewById(R.id.imageViewTodo); 
     ImageView ivIdea = (ImageView) dialogView.findViewById(R.id.imageViewIdea); 

     if (!mNote.isImportant()){ 
      ivImportant.setVisibility(View.GONE); 
     } 

     if (!mNote.isTodo()){ 
      ivTodo.setVisibility(View.GONE); 
     } 

     if (!mNote.isIdea()){ 
      ivIdea.setVisibility(View.GONE); 
     } 

     Button btnOK = (Button) dialogView.findViewById(R.id.btnOK); 

     builder.setView(dialogView).setMessage("Your mNote"); 

     btnOK.setOnClickListener(new View.OnClickListener() { 
      @Override 
      public void onClick(View v) { 
       dismiss(); 
      } 
     }); 

     return builder.create(); 
    } 


    public void sendNoteSelected(Note noteSelected) { 
     mNote = noteSelected; 
    } 
} 

およびその関連レイアウト。

<?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:paddingLeft="10dp" 
        android:paddingTop="10dp" 
        android:paddingRight="10dp" 
        android:paddingBottom="20dp"> 

     <ImageView 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:id="@+id/imageViewImportant" 
      android:layout_alignParentTop="true" 
      android:layout_alignParentLeft="true" 
      android:layout_alignParentStart="true" 
      android:src="@drawable/ic_warning_black_24dp" /> 

     <ImageView 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:id="@+id/imageViewTodo" 
      android:layout_alignParentTop="true" 
      android:layout_toRightOf="@+id/imageViewImportant" 
      android:layout_toEndOf="@+id/imageViewImportant" 
      android:src="@drawable/ic_check_box_outline_blank_black_24dp" /> 

     <ImageView 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:id="@+id/imageViewIdea" 
      android:layout_alignParentTop="true" 
      android:layout_toRightOf="@+id/imageViewTodo" 
      android:layout_toEndOf="@+id/imageViewTodo" 
      android:src="@drawable/ic_wb_incandescent_black_24dp" /> 

     <TextView 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:textAppearance="?android:attr/textAppearanceLarge" 
      android:text="Large Text" 
      android:id="@+id/txtTitle" 
      android:layout_below="@+id/imageViewIdea" 
      android:layout_centerHorizontal="true" 
      android:layout_marginTop="27dp" /> 

     <TextView 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:text="New Text" 
      android:id="@+id/txtDescription" 
      android:layout_marginTop="34dp" 
      android:layout_below="@+id/txtTitle" 
      android:layout_alignParentLeft="true" 
      android:layout_alignParentStart="true" /> 

     <Button 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:text="OK" 
      android:id="@+id/btnOK" 
      android:layout_alignParentBottom="true" 
      android:layout_alignLeft="@+id/txtTitle" 
      android:layout_alignStart="@+id/txtTitle" 
      android:layout_marginBottom="28dp" /> 
    </RelativeLayout> 
+0

でできたものもあると考えています3つのイメージビューがありますか? – rmanalo

+0

メモにこれらのオプションが設定されている場合、3つの画像ビューが表示されます。このオプションは、この場合はView.GONEに設定されています。テキストビューではどういう意味ですか?この例では、通常の文字列リテラルを渡してメッセージを設定しています。 – 0123

+0

ダイアログの上部にあるものは何ですか? – rmanalo

答えて

1

私は同じ本から同じことをして、同じ結果を得ています。私は私の新しいノートダイアログがうまくいきますが、ノートノートダイアログがこれをしていることを知っています。

私が見ていることから、これは、一部のデバイスがAlertDialogsでsetMessage呼び出しを処理する方法が原因で発生します。彼らはこのようにテキストを断ちました。回避策は、「Your mNote」と書かれている他のウィジェットの上のレイアウトにPlain TextViewウィジェットを実際に配置することです。

残念ながら、setMessage関数で処理するだけでなく、計画しなければならないもののように見えます。 XMLに

変更

builder.setView(dialogView).setMessage("Your mNote"); 

builder.setView(dialogView); 

テキスト "あなたmNote" と平野のTextViewを追加するには、(それは少し似ていますので、私はAlertDialog.AppCompatへのスタイルを設定しました)ショーノートのために。

とし、その下の他のすべてをフォーマットします。

私は、これはrmanaloは、カットオフのためのTextViewがテキスト「あなたmNote」であり、なぜある彼の「カットオフのためのTextViewがある...」