0

私はAndroidアプリをプログラミングしていて、テーブルを表示しようとしています。私の問題は、列が画面いっぱいに表示されず、すべてが左に固定されることです。

すでにパディングを使用してみましたが、最初はすべてのディスプレイ解像度と互換性があるとは思いません。次に、コンテンツが異なる場合、列の配置が異なります。

それから私は重量について読みました、そしてこれはまさに私が望んでいたものであり、すべての列に画面の幅の特定のパーセンテージを与えました。しかし、重みは細胞が再び左にくっつくことにつながりました。彼らは私が設定した重みにまったく反応しませんでした。

ビューをxmlテンプレートでプログラムし、LayoutInflaterを使用してプログラムで膨らませます。次に、それらを対応するTableRowに追加します。これらはすべて完全に正常に機能しますが、重みに反応しません。

よろしくお願いします。

編集:テンプレートはスタイルを参照し、次のようになります:

<?xml version="1.0" encoding="UTF-8"?>
<TextView xmlns:android="http://schemas.android.com/apk/res/android"
style="@style/scheduleClass" />

そして、スタイルは次のようになります。

<?xml version="1.0" encoding="utf-8"?>
<resources>
    <style name="scheduleItem" parent="@android:style/TextAppearance.Medium">
        <item name="android:layout_width">0dp</item>
        <item name="android:layout_height">wrap_content</item>
        <item name="android:paddingRight">0dp</item>
        <item name="android:paddingBottom">10dp</item>
    </style>
    <style name="scheduleClass" parent="scheduleItem">
        <item name="android:layout_weight">0.2</item>
    </style>
</resources>

他にもいくつかの列がありますが、それらには別の名前と別の重みがあります。

そして、これが私がテーブルにビューを追加する方法です:

public void updateList(ArrayList<Lesson> lessons) {
    setContentView(R.layout.schedule);
    TableLayout table = (TableLayout) findViewById(R.id.table);

    for(Lesson cancel : lessons) {
        TableRow row = new TableRow(this);

        TextView date = (TextView) this.getLayoutInflater().inflate(R.layout.scheduledatetemplate, null);
        date.setText(cancel.date);

        TextView classname = (TextView) this.getLayoutInflater().inflate(R.layout.scheduleclasstemplate, null);
        classname.setText(cancel.classname);

        TextView lesson = (TextView) this.getLayoutInflater().inflate(R.layout.schedulelessontemplate, null);
        lesson.setText(cancel.lesson);

        Button details = (Button) this.getLayoutInflater().inflate(R.layout.detailsbuttontemplate, null);
        details.setText(R.string.details);
        details.setOnClickListener(this);

        row.addView(date);
        row.addView(classname);
        row.addView(lesson);
        row.addView(details);

        table.addView(row);
    }
}

そしてこれはTableLayoutxmlです:

<?xml version="1.0" encoding="utf-8"?>

<ScrollView  xmlns:android="http://schemas.android.com/apk/res/android"
    android:scrollbars="vertical"
    android:layout_height="fill_parent"
    android:layout_width="fill_parent">

    <TableLayout xmlns:android="http://schemas.android.com/apk/res/android"
        android:id="@+id/table"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:scrollbars="vertical">

    </TableLayout>
</ScrollView>
4

1 に答える 1

0

あなたはあなたのに宣言し、属性を付ける必要がandroid:layout_columnありandroid:layout_spanますTableRow

http://developer.android.com/reference/android/widget/TableRow.LayoutParams.htmlを参照してください

ここで例を参照してください: http ://www.mkyong.com/android/android-tablelayout-example/

更新:わかりました。作成する各行にlayout_spanとlayout_columnを設定する必要があります。次のaddViewメソッドを使用してください:http: //developer.android.com/reference/android/widget/TableLayout.html#addView (android.view.View、int、android.view.ViewGroup.LayoutParams)

レイアウトパラメータに適切な列とスパンを指定し、行のスパンをテーブル全体に設定し、行のgravity = centerを指定して、コンテンツを中央に配置します。

また、テーブル属性strechColumns http://developer.android.com/reference/android/widget/TableLayout.html#attr_android:stretchColumns は、次のように役立ちます。

android:strechColumns="*"

またはそのようなもの。

于 2012-08-19T21:04:08.757 に答える