2012-12-22 8 views
9

Mam okno dialogowe z ostrzeżeniem, które jest uruchamiane, gdy ktoś dotknie konkretnego przycisku. Okno alertu zawiera widok zdefiniowany przez plik xml układu. Ten układ zawiera kilka elementów sterujących, takich jak pola wyboru, pola tekstowe edycji ... Te elementy sterujące znajdują się wewnątrz widoku scroola, dzięki czemu można przewijać zawartość, jeśli cała treść nie mieści się na ekranie.Przyciski okna ostrzeżenia są obcięte

Problem polega na tym, że po uruchomieniu tego okna dialogowego z ostrzeżeniem przyciski u dołu ekranu są obcięte. Mimo że pasek Scroola działa i mogę przewijać treść okna dialogowego alertu, przyciski okna dialogowego alertu czasami nie są całkowicie widoczne.

Oznacza to: To znaczy: Czasami wszystko jest w porządku i widzę przyciski w oknie dialogowym alertu, czasami z dziwnego powodu, przyciski są obcięte. Myślę, że to kwestia dużego widoku okna alertu i wciskania przycisków w dół. Na przykład widok zawiera kontrolkę edycji tekstu. Jeśli wejdę na moje nazwisko, wszystko będzie dobrze. Ale jeśli dodaję nową linię do tego edytowanego tekstu, przyciski zaczną być nieco przycięte. Co ja źle zrobiłem? Sądziłem, że widok przewijania poradzi sobie z nadwymiarością mojego widoku, dzięki czemu okno alertu będzie pasować do ekranu. Moja aplikacja jest zawsze w trybie portretu.

Kod zdania:

<ScrollView xmlns:android="http://schemas.android.com/apk/res/android" 
    android:id="@+id/scrollView2" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    android:fillViewport="true" > 

    <LinearLayout 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:orientation="vertical" 
     android:padding="5dp" > 

     <TextView 
      android:id="@+id/textView1" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:text="@string/bitteeinstellungenwaehlen" /> 

     <EditText 
      android:id="@+id/edtTeam1" 
      android:layout_width="match_parent" 
      android:layout_height="wrap_content" 
      android:ems="10" 
      android:hint="@string/hteam1" 
      android:text="Christoph" > 

      <requestFocus /> 
     </EditText> 

     <EditText 
      android:id="@+id/edtTeam2" 
      android:layout_width="match_parent" 
      android:layout_height="wrap_content" 
      android:ems="10" 
      android:hint="@string/hteam2" 
      android:text="Lea" /> 

     <EditText 
      android:id="@+id/edtTeam3" 
      android:layout_width="match_parent" 
      android:layout_height="wrap_content" 
      android:ems="10" 
      android:hint="@string/hteam3" 
      android:text="Ludwig" /> 

     <EditText 
      android:id="@+id/edtTeam4" 
      android:layout_width="match_parent" 
      android:layout_height="wrap_content" 
      android:ems="10" 
      android:hint="@string/hteam4" 
      android:text="Anja" /> 

     <TextView 
      android:id="@+id/textView2" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:text="@string/weitereeinstellungen" /> 

     <LinearLayout 
      android:layout_width="match_parent" 
      android:layout_height="wrap_content" > 

      <CheckBox 
       android:id="@+id/chkModerationMode" 
       android:layout_width="wrap_content" 
       android:layout_height="wrap_content" 
       android:text="@string/moderationsmodus" /> 

      <TextView 
       android:id="@+id/textView3" 
       android:layout_width="wrap_content" 
       android:layout_height="wrap_content" 
       android:layout_marginLeft="10dp" 
       android:text="@string/info" /> 

     </LinearLayout> 

     <CheckBox 
      android:id="@+id/chkPassOver" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:checked="true" 
      android:text="@string/weitergeben" /> 

     <CheckBox 
      android:id="@+id/chkBlackScreen" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:text="@string/blankscreen" /> 

    </LinearLayout> 

</ScrollView> 

I tak zacznę alertu okno dialogowe:

final AlertDialog.Builder alert = new AlertDialog.Builder(QuizEditor.this); 

    alert.setTitle(getString(R.string.speichernUndVorschau) + "..."); 
    alert.setMessage(""); 


    LayoutInflater inflater = LayoutInflater.from(QuizEditor.this); 
    final View layFrage = inflater.inflate(R.layout.layoutquizsettings,null); 
    alert.setView(layFrage); 

    final CheckBox chkModeration = (CheckBox) layFrage.findViewById(R.id.chkModerationMode); 
    final CheckBox chkPassOver = (CheckBox) layFrage.findViewById(R.id.chkPassOver); 
    final CheckBox chkBlackScreen = (CheckBox) layFrage.findViewById(R.id.chkBlackScreen); 

    final EditText edtTeam1 = (EditText) layFrage.findViewById(R.id.edtTeam1); 
    final EditText edtTeam2 = (EditText) layFrage.findViewById(R.id.edtTeam2); 
    final EditText edtTeam3 = (EditText) layFrage.findViewById(R.id.edtTeam3); 
    final EditText edtTeam4 = (EditText) layFrage.findViewById(R.id.edtTeam4); 



    alert.setNeutralButton(getString(R.string.speichernUndVorschau), new DialogInterface.OnClickListener() { 
    public void onClick(DialogInterface dialog, int whichButton) { 




    } 
    }); 

    alert.setNegativeButton(getString(R.string.abbrechen), new DialogInterface.OnClickListener() { 
     public void onClick(DialogInterface dialog, int whichButton) { 
     // Canceled. 
     } 
    }); 



    final AlertDialog dialog2 = alert.create(); 

    dialog2.setOnShowListener(new OnShowListener() { 

     @Override 
     public void onShow(DialogInterface dialog) { 
      // TODO Auto-generated method stub 
      Button btnStarten = (Button) dialog2.getButton(AlertDialog.BUTTON_NEUTRAL); 
      btnStarten.setOnClickListener(new OnClickListener() { 

       @Override 
       public void onClick(View v) { 
        // TODO Auto-generated method stub 
        ArrayList<String> teams = new ArrayList<String>(); 

        String team1 = edtTeam1.getText().toString().trim(); 
        String team2 = edtTeam2.getText().toString().trim(); 
        String team3 = edtTeam3.getText().toString().trim(); 
        String team4 = edtTeam4.getText().toString().trim(); 

        if(team1.length() > 0) teams.add(team1); 
        if(team2.length() > 0) teams.add(team2); 
        if(team3.length() > 0) teams.add(team3); 
        if(team4.length() > 0) teams.add(team4); 

        if(teams.size() == 0) { 
         Toast.makeText(QuizEditor.this, getString(R.string.keinteameingegeben), Toast.LENGTH_SHORT).show(); 

        } 
        else 
        { 
         // Quiz starten 



         dialog2.dismiss(); 
         Intent myIntent; 

         if(chkBlackScreen.isChecked()) { 
          myIntent = new Intent(QuizEditor.this, BlackScreen.class); 
         } 
         else // Direkt das Quiz starten 
         { 
          myIntent = new Intent(QuizEditor.this, Quiz.class); 
         } 


         myIntent.putStringArrayListExtra("teams", teams); 
         myIntent.putExtra("moderation", chkModeration.isChecked()); 
         myIntent.putExtra("passover", chkPassOver.isChecked()); 
         myIntent.putExtra("filename", filename); 


         QuizEditor.this.startActivity(myIntent); 
        } 
       } 

      }); 

     } 

    }); 

    dialog2.show(); 
    // dialog2.getWindow().setLayout(LayoutParams.WRAP_CONTENT, 300); 

Żałuję dla niemieckich słów. Na obrazie widać problem. Niestety nie mogłem przesłać zrzuty ekranu zrobiłem ...

+2

Okay dzięki za pomoc! Na szczęście znalazłem mistakte: alert.setMessage (""); Ponieważ usunąłem tę linię, wszystko działa dobrze. – Chris623

+0

samo tutaj, thx dla tego rozwiązania. Komischer fehler und schwer zu finden danke dafür =) –

Odpowiedz

0

Ustaw linie EditText na 1. Ustaw również zewnętrzny LinearLayout na fill_parent.

0

Po prostu wykonaj całą właściwość EditTextandroid:singleLine="true", a następnie spróbuj ją przetestować.

0

Pytanie już zostało rozwiązane w komentarzach, ale dodam odpowiedź na kompletność i pokażę, że zadziałało również dla mnie.

W przypadku modelu AlertDialog z niestandardowym widokiem nie należy używać linii .setMessage. Usunięcie następującego wiersza w moim projekcie spowodowało, że przyciski przestały być przycinane.

.setMessage("This is my message") 
Powiązane problemy