die dynamische Erstellung von tablelayout (android)
Will ich schaffen inneren tablelayout und fügen es 1 Zeile mit 2 Spalten folgende code zeigt nichts an, warum?
Hier Haupttätigkeit:
public class TestActivity extends Activity {
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
LayoutParams params = new LinearLayout.LayoutParams(LayoutParams.FILL_PARENT,
LayoutParams.WRAP_CONTENT);
TextView tv1 = new TextView(this);
TextView tv2=new TextView(this);
tv1.setLayoutParams(params);
tv2.setLayoutParams(params);
tv1.setText("Hello1!");
tv2.setText("Hello2!");
TableLayout layoutINNER = new TableLayout(this);
layoutINNER.setLayoutParams(params);
TableRow tr = new TableRow(this);
tr.setLayoutParams(params);
tr.addView(tv1);
tr.addView(tv2);
layoutINNER.addView(tr);
LinearLayout main = (LinearLayout)findViewById(R.id.android_main_layout);
main.addView(layoutINNER);
}
}
XML:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/android:main_layout"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
>
</LinearLayout>
UPDATE:
Gut, endlich habe ich dieses problem gelöst, es war nur nötig, um Tabellenzeilen.LayoutParams mit TextViews, nicht LinearLayout.LayoutParams oder einige andere
Haben Sie versucht, mit
Hier ist, was du suchst: warriorpoint.com/blog/2009/07/01/...
ich habe vor kurzem versucht, es funktioniert nicht, zu
TableLayout.LayoutParams
statt für Ihre TextViews
und die TableRow
?Hier ist, was du suchst: warriorpoint.com/blog/2009/07/01/...
ich habe vor kurzem versucht, es funktioniert nicht, zu
InformationsquelleAutor user1049280 | 2011-12-02
Du musst angemeldet sein, um einen Kommentar abzugeben.
Hier ist der funktionierende code:
InformationsquelleAutor ruben