ich das folgende Layout programmatisch gemacht:Margins nicht funktioniert
LinearLayout progressLayout = new LinearLayout(this);
progressLayout.setOrientation(LinearLayout.VERTICAL);
TextView t = new TextView(this);
t.setText("Test..");
t.setTextSize(TypedValue.COMPLEX_UNIT_DIP, 20);
LayoutParams l = new LayoutParams(android.view.ViewGroup.LayoutParams.WRAP_CONTENT, android.view.ViewGroup.LayoutParams.WRAP_CONTENT);
l.setMargins(10, 10, 10, 25); ===> does not work?
t.setLayoutParams(l);
ProgressBar circle = new ProgressBar(this, null,
android.R.attr.progressBarStyleLarge);
circle.setLayoutParams(new LayoutParams(android.view.ViewGroup.LayoutParams.WRAP_CONTENT, android.view.ViewGroup.LayoutParams.WRAP_CONTENT));
progressLayout.setLayoutParams(new LayoutParams(
android.view.ViewGroup.LayoutParams.FILL_PARENT,
android.view.ViewGroup.LayoutParams.FILL_PARENT));
progressLayout.setGravity(Gravity.CENTER);
progressLayout.addView(t);
progressLayout.addView(circle);
this.setContentView(progressLayout);
Aber: Egal, was ich als Wert in setMargins geben, macht es keinen Effekt hat überhaupt.
Was ist der Grund?
Das Layout hat eine Höhe und Breite von fill_parent, so dass nicht das Problem sein kann ..
Thx :)
welche Art von LayoutParams verwenden Sie? – njzk2
RelativeLayout.LayoutParams –
Sie sollten eine LinearLayout.LayoutParams verwenden, da Sie die Ansicht in eine LinearLayout setzen (obwohl dies nicht das Problem sein sollte, da beide MarginLayoutParams sind) – njzk2