2016-07-11 6 views
0

Ich habe ein Problem mit meiner App und ich kann keine rationale Erklärung finden, warum das passiert ist. Ich dynamisch erstellen Dialogfeld:Android Studio: dynamisch erstellten Tastenlayout ist beschnitten

final Dialog dialog = new Dialog(content); 
dialog.requestWindowFeature(Window.FEATURE_NO_TITLE); 
dialog.setCancelable(false); 
dialog.setCanceledOnTouchOutside(false); 
dialog.getWindow().setLayout(LinearLayout.LayoutParams.MATCH_PARENT, LinearLayout.LayoutParams.MATCH_PARENT); 
LinearLayout popUp = getProperLayout(s1,content); 
popUp = generateFinalLayout(s,popUp,content); 
// Button 
LinearLayout btnLayout = new LinearLayout(content); 
btnLayout.setOrientation(LinearLayout.HORIZONTAL); 
btnLayout.setGravity(Gravity.RIGHT); 
btnLayout.setPadding(8,0,8,12); 
Button cancel = new Button(content); 
cancel.setText("OK"); 
cancel.setBackgroundColor(Color.TRANSPARENT); 
cancel.setTextColor(Color.parseColor("#0078ff")); 
cancel.setOnClickListener(new View.OnClickListener() { 
    @Override 
     public void onClick(View view) { 
      dialog.cancel(); 
     } 
    }); 
btnLayout.addView(cancel); 
//Dodaj 
popUp.addView(btnLayout); 
dialog.setContentView(popUp); 

getProperLayout:

public static LinearLayout getProperLayout(String s1,Context content) { 
    LinearLayout properLayout; 
    properLayout = new LinearLayout(content); 
    properLayout.setOrientation(LinearLayout.VERTICAL); 
    properLayout.setBackgroundColor(Color.parseColor("#EEEEEE")); 
    properLayout.setPadding(16,16,16,16); 
    LinearLayout.LayoutParams params = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT,LinearLayout.LayoutParams.MATCH_PARENT); 
    properLayout.setLayoutParams(params); 
    // Treść informacji 
    TextView nameText = new TextView(content); 
    nameText.setText(s1); 
    nameText.setPadding(16, 36, 16, 36); 
    nameText.setGravity(Gravity.CENTER_HORIZONTAL); 
    //Dodaj wszycho 
    properLayout.addView(nameText); 
    return properLayout; 
} 

generateFinalLayout:

public static LinearLayout generateFinalLayout(String title,LinearLayout popUp,Context content) { 
    LinearLayout properLayout; 
    properLayout = new LinearLayout(content); 
    properLayout.setOrientation(LinearLayout.VERTICAL); 
    properLayout.setBackgroundColor(Color.parseColor("#EEEEEE")); 
    LinearLayout.LayoutParams params = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.WRAP_CONTENT,LinearLayout.LayoutParams.WRAP_CONTENT); 
    properLayout.setLayoutParams(params); 
    // Tytuł 
    TextView titleTv = new TextView(content); 
    titleTv.setText(title); 
    titleTv.setTextSize(20f); 
    titleTv.setTextColor(Color.WHITE); 
    titleTv.setBackgroundColor(Color.parseColor("#0056BB"));//29394E")); 
    titleTv.setTypeface(null, Typeface.BOLD); 
    titleTv.setPadding(16, 16, 16, 16); 
    // Poszerzacz 
    TextView extender = new TextView(content); 
    extender.setBackgroundColor(Color.parseColor("#2278DD"));//Color.parseColor("#18283d")); 
    params = new LinearLayout.LayoutParams(712,0); 
    extender.setLayoutParams(params); 
    extender.setPadding(2, 22, 2, 22); 
    // Poszerzacz2 
    TextView extender2 = new TextView(content); 
    extender2.setBackgroundColor(Color.TRANSPARENT);//Color.parseColor("#18283d")); 
    params = new LinearLayout.LayoutParams(712,4); 
    extender2.setLayoutParams(params); 
    extender2.setPadding(2, 22, 2, 22); 
    // Dodajparams 
    properLayout.setPadding(0,0,0,0); 
    properLayout.addView(titleTv); 
    properLayout.addView(extender); 
    properLayout.addView(popUp); 
    properLayout.addView(extender2); 
    return properLayout; 
} 

Und auf vielen Geräten (S3, LG V490, S5, S7) ist es ok aussieht. Aber auf dem HTC des Klienten sieht es so aus: enter image description hereenter image description here

Irgendeine Idee, warum geschieht dieses? Entfernen Polsterung löst nichts ...

+0

Dialog dynamisch erstellt wird, und es gibt keine xml, aber ich habe vergessen generateFinaLayout Code zu setzen. Bearbeitung. –

+0

Bitte lassen Sie mich wissen, die Verwendung von zwei Methoden in den folgenden Zeilen LinearLayout popUp = getProperLayout (s1, Inhalt); popUp = generateFinalLayout (s, PopUp, Inhalt); bedeutet getProperLayout und generateFinalLayout –

+0

Dort gehen Sie, fügte ich sie in Frage. Entschuldigen Sie das Durcheinander. –

Antwort

0
final Dialog dialog = new Dialog(MainActivity.this); 
      dialog.requestWindowFeature(Window.FEATURE_NO_TITLE); 
      dialog.setCancelable(false); 
      dialog.setCanceledOnTouchOutside(false); 
      dialog.getWindow().setLayout(LinearLayout.LayoutParams.MATCH_PARENT, LinearLayout.LayoutParams.MATCH_PARENT); 
      LinearLayout popUp = getProperLayout("Proper",MainActivity.this); 
      popUp = generateFinalLayout("Final",popUp,MainActivity.this); 
      // Button 
      LinearLayout btnLayout = new LinearLayout(MainActivity.this); 
      btnLayout.setOrientation(LinearLayout.HORIZONTAL); 
      btnLayout.setGravity(Gravity.RIGHT); 
      btnLayout.setPadding(8,0,8,12); 
      Button cancel = new Button(MainActivity.this); 
      cancel.setText("OK"); 
      cancel.setBackgroundColor(Color.TRANSPARENT); 
      cancel.setTextColor(Color.parseColor("#0078ff")); 
      cancel.setOnClickListener(new View.OnClickListener() { 
       @Override 
       public void onClick(View view) { 
        dialog.cancel(); 
       } 
      }); 
      btnLayout.addView(cancel); 
      //Dodaj 
      popUp.addView(btnLayout); 
      dialog.setContentView(popUp); 
      dialog.show(); 

sonst gleichen

+0

Ein paar Worte der Erklärung, was du geändert hast und warum es wirklich toll wäre! –