Einstellung der layout_weight der TextView unter der Tabellenzeilen

Diese Frage ist eigentlich im Zusammenhang mit diesem post Setzen Sie die layout-Gewicht von einem TextView-programmgesteuert

Basierend auf den Antworten, die ich nur brauche, um die TextView layout params wie folgt, und legen Sie die stretchColumn Eigentum, sondern indem Sie den folgenden code, um mir, es macht die textView verschwinden aus der Tabelle Layout.

TextView tv = new TextView(v.getContext());
tv.setLayoutParams(new LinearLayout.LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT, 1f));

So, hier ist mein code wo ich will Sie dynamisch hinzufügen eine Zeile mit 3 Spalten mit 35%, 5% und 60% Gewicht. Bitte lassen Sie mich wissen, was ist Los mit meinem code.

private void addTableRow(int resIdTitle, String strValue){

        TableRow tr = new TableRow(this);

        //Add First Column
        TextView tvTitle = new TextView(this);
        tvTitle.setText(resIdTitle);
        tvTitle.setLayoutParams(new LinearLayout.LayoutParams(LayoutParams.WRAP_CONTENT, 
                LayoutParams.WRAP_CONTENT, 0.35f));
        tr.addView(tvTitle);

        //Add 2nd Column
        TextView tvColon = new TextView(this);
        tvColon.setText(" : ");
        tvColon.setLayoutParams(new LinearLayout.LayoutParams(LayoutParams.WRAP_CONTENT, 
                LayoutParams.WRAP_CONTENT, 0.05f));
        tr.addView(tvColon);

        //Add the 3rd Column
        TextView tvValue = new TextView(this);
        tvValue.setText(strValue);
        tvValue.setLayoutParams(new LinearLayout.LayoutParams(LayoutParams.WRAP_CONTENT, 
                LayoutParams.WRAP_CONTENT, 0.60f));
        tr.addView(tvValue);

        //Finally add it to the table
        tl.addView(tr, new TableLayout.LayoutParams(
                LayoutParams.FILL_PARENT,
                LayoutParams.WRAP_CONTENT));
        Log.d(TAG, "Row Added");
    }

Und hier ist meine xml-Datei,

<?xml version="1.0" encoding="utf-8"?>
<ScrollView
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:layout_weight="1">
    <TableLayout
      android:id="@+id/tl_cam_get_param"
      android:layout_width="match_parent"
      android:layout_height="match_parent"
      android:title="@string/strGetParamTitle" 
      android:scrollbars="vertical"       
      android:shrinkColumns="0">
        </TableLayout>
</ScrollView>

Ich habe auch versucht, die Einstellung der layout_width auf 0, aber noch hat es nicht funktioniert.

Dank,

artsylar

InformationsquelleAutor artsylar | 2011-07-14

Schreibe einen Kommentar