1

簡単な質問がありますScrollView

たとえば、次のレイアウトがある場合:

<LinearLayout
    android:id="@+id/wrapper_table"
    android:layout_width="match_parent"
    android:orientation="vertical"
    android:layout_height="match_parent">

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content">     
    </LinearLayout>

    <ScrollView
        android:layout_width="match_parent"
        android:layout_height="match_parent">

        <TableLayout
            android:layout_width="match_parent"
            android:layout_height="wrap_content">
        </TableLayout>
    </ScrollView>

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent">     
    </LinearLayout>

</LinearLayout>

TheTableLayoutに多くTableRowの場合Scrollview、 は画面の端まで拡大され、下部LinearLayoutは表示されなくなります。ScrollView下部を表示するのに十分なスペースを確保するために、高さを設定せずに高さを強制することは可能LinearLayoutですか?

ありがとうございました!!

4

2 に答える 2

0

に を適用android:layout_weightScrollViewます。このようにして、他の要素によって占有されていないスペースをすべて占有します。

以下の調整では、2 つLinearLayoutの はコンテンツを収容するのに十分なスペースを占有し、ScrollViewは残りのすべてを占有します。

<LinearLayout
    android:id="@+id/wrapper_table"
    android:layout_width="match_parent"
    android:orientation="vertical"
    android:layout_height="match_parent">

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content">    
    </LinearLayout>

    <!-- This should be weighted height -->
    <ScrollView
        android:layout_width="match_parent"
        android:layout_height="0px"
        android:layout_weight="1">

        <TableLayout
            android:layout_width="match_parent"
            android:layout_height="wrap_content">
        </TableLayout>
    </ScrollView>

    <!-- This should be wrap_content height -->
    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content">    
    </LinearLayout>

</LinearLayout>
于 2012-11-09T16:42:55.000 に答える
0

はい、外側の線形レイアウトで、「android:layout_weight」を各要素に設定し、外側のレイヤーに「weightSum」を指定させます

そのようです:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
    android:id="@+id/wrapper_table"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical"
    android:weightSum="1">

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="0dip"
        android:layout_weight="0.1">     
    </LinearLayout>

    <ScrollView
        android:layout_width="match_parent"
        android:layout_height="0dip"
        android:layout_weight="0.8">

        <TableLayout
            android:layout_width="match_parent"
            android:layout_height="match_parent">
        </TableLayout>
    </ScrollView>

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="0dip"
        android:layout_weight="0.1">     
    </LinearLayout>

</LinearLayout>

「weightSum」と「layout_weight」は、使用する画面の比率を指定します。私の例では、下部と上部がそれぞれ画面の 10% を占め、80% を中央のスクロールビューとして残します (テーブルビューで埋められます)。

今、高さを「match_parent」に変更する必要があると思います。これは、画面の 80% すべてを占めるようにするためです...再確認してください...

(SDK とエディターのバージョンに応じて) 変更する必要があるもう 1 つのことは、各内部要素の「layout_height」を「0dip」にすることです。そうしないと、このメカニズムが機能しないか、エラーが発生する可能性があります。

于 2012-11-09T16:39:01.117 に答える