0
내 앱에 문제가 있으며 왜 이런 일이 발생하는지 합리적으로 설명 할 수 없습니다. Android Studio : 동적으로 생성 된 버튼 레이아웃이 잘립니다.
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;
}
그리고 많은 장치 (S3, LG V490, S5, S7)에
이 좋아 보이는 :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 동적으로 대화 상자 만듭니다. 그러나 클라이언트의 HTC에는 다음과 같습니다
어떤 생각, 왜 이런 일이? 아무것도 해결되지 제거 패딩 ... 다른
대화가 동적으로 생성되는 동일 어떠한 XML이 없다,하지만 난 generateFinaLayout 코드를 넣어 잊어 버렸습니다. 편집 중. –
아래 두 줄의 두 가지 방법을 알려주십시오. LinearLayout popUp = getProperLayout (s1, content); popUp = generateFinalLayout (s, popUp, content); 은 getProperLayout 및 generateFinalLayout을 의미합니다. –
저기, 내가 질문에 추가했습니다. 혼란을 드려 죄송합니다. –