2

アクティビティで DB からのデータを表示しています。下部にテーブルとボタンが必要です。データの場合、 TableLayout が最適なオプションになると考えられていました。TableLayout を Horizo​​ntalView と 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>

出力: ここに画像の説明を入力

4

2 に答える 2

5

Horizo ​​ntalScrollView内で使用した場合のTableLayoutについて、問題を解決しているときに 1 つのことがわかりました。水平スクロール ビュー内でテーブル レイアウトを使用すると、android:stretchColumnsが機能しません。画面が回転したり、列の幅のデータが少ないときに空白ができるようにします。

これを理解していただければ幸いです。Horizo​​ntal Scroll View を他のものに置き換えることで、この問題を解決しようとしています。解決策が得られたら、回答を投稿します。さよなら。

編集

こんにちはTvdついに私はあなたの問題の解決策を得ました. XML レイアウト ファイルに以下の変更を加えます。

<HorizontalScrollView>

使用する

        android:layout_width="fill_parent" 
        android:layout_height="wrap_content"
        android:fillViewport="true"

すべての列を拡大する場合は、 TableLayoutで使用stretchColumns = "*"します。

さよなら。:-)

于 2012-02-03T09:06:52.870 に答える
0

私はいくつかの変更を行いました。あなたの問題のいくつかは、以下のレイアウトコードで解決します

 <?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:layout_weight="1"
    android:scrollbars="horizontal|vertical" >

    <HorizontalScrollView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_marginBottom="10dp"
        android:layout_marginTop="10dp" >

        <TableLayout
            android:id="@+id/browseTable"
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:layout_marginBottom="20dp"
            android:background="#FF0000" >
        </TableLayout>
    </HorizontalScrollView>
</ScrollView>

<LinearLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    style="@android:style/ButtonBar"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:gravity="center"
    android:orientation="horizontal" >

    <Button
        android:id="@+id/browseAddBtn"
        android:layout_width="0dp"
        android:layout_height="wrap_content"
        android:layout_marginRight="10dp"
        android:layout_weight="1"
        android:text="Add" />

    <Button
        android:id="@+id/browseViewBtn"
        android:layout_width="0dp"
        android:layout_height="wrap_content"
        android:layout_marginRight="10dp"
        android:layout_weight="1"
        android:text="Edit" />

    <Button
        android:id="@+id/browseReturnBtn"
        android:layout_width="0dp"
        android:layout_height="wrap_content"
        android:layout_weight="1"
        android:text="Return" />
</LinearLayout>

于 2012-01-23T10:55:37.497 に答える