アクティビティで DB からのデータを表示しています。下部にテーブルとボタンが必要です。データの場合、 TableLayout が最適なオプションになると考えられていました。TableLayout を HorizontalView と ScrollView に追加して、垂直方向と水平方向にスクロールできるようにしました。ヘッダーを含むすべての行を動的に追加しています。この部分は正常に動作しています。
コンテンツが画面幅よりも小さい場合でも、画面幅全体を占める必要があります。たとえば。テーブルがポートレート モードにうまく収まる場合、もちろんランドスケープ モードでは右側に空白が残ります。そのスペースが空っぽになるのではなく、すべての列が占めるようにしたくありません。行幅が画面幅よりも大きい場合、水平スクロールバーが表示されるため、まったく問題はありません。
いくつかのバリエーションを試しましたが、何も役に立ちませんでした。すべてのスペースを利用するためにどのような設定を行うべきか(avblがあれば)、それを表示するアイデア。
はい、水平スクロールバーのもう 1 つの問題は、最後の行に表示されます。最後の行の下に表示したいので、最後の行の境界線が表示されます。私のXML:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent" android:orientation="vertical">
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent" android:layout_height="wrap_content"
android:scrollbars="horizontal|vertical">
<HorizontalScrollView android:layout_width="wrap_content" android:layout_height="wrap_content"
android:layout_marginTop="10dp" android:layout_marginBottom="10dp" >
<TableLayout android:id="@+id/browseTable" android:layout_width="fill_parent"
android:layout_height="wrap_content" android:layout_marginBottom="20dp"
android:background="#FF0000" android:stretchColumns="1,2,3">
</TableLayout>
</HorizontalScrollView>
</ScrollView>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent" android:layout_height="wrap_content"
android:orientation="horizontal" android:gravity="center"
android:layout_marginTop="15dp">
<Button android:id="@+id/browseAddBtn" android:text="Add" android:layout_width="0dp" android:layout_height="wrap_content" android:layout_weight="1" android:layout_marginRight="10dp" />
<Button android:id="@+id/browseViewBtn" android:text="Edit" android:layout_width="0dp" android:layout_height="wrap_content" android:layout_weight="1" android:layout_marginRight="10dp" />
<Button android:id="@+id/browseReturnBtn" android:text="Return" android:layout_width="0dp" android:layout_height="wrap_content" android:layout_weight="1" />
</LinearLayout>
</LinearLayout>
出力: