私は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>