6

Androidデバイス用のアプリを作成していて、LinearLayout内にScrollViewを配置しようとしていますが、これを実行しようとすると、ScrollViewはLinearLayoutのScrollViewの後にあるすべてのスペースと要素を取得します。

例:
ScrollViewが「フル」でない 場合:ScrollViewが「フル」の場合:
http://kakko76.free.fr/scroll2.jpg

http://kakko76.free.fr/scroll1.png

ボタンが消えているのがわかるように...
このアクティビティのコードは次の とおりです。

<LinearLayout
    android:id="@+id/linearLayout1"
    android:layout_width="fill_parent"
    android:layout_marginLeft="50dp"
    android:layout_height="wrap_content"
    android:layout_centerHorizontal="true"
    android:layout_centerVertical="true"
    android:orientation="vertical"
    android:focusable="true"
    android:focusableInTouchMode="true"
    android:background="@drawable/linearlayoutbackground" >

    <TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="@string/nom_des_joueurs"
        android:textAppearance="?android:attr/textAppearanceLarge"
        android:layout_marginBottom="30dp" />

    <ScrollView
        android:id="@+id/scrollView1"
        android:layout_width="match_parent"
        android:layout_height="wrap_content">

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

        </LinearLayout>

    </ScrollView>

    <Button
        android:id="@+id/okPlayersName"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:text="@string/ok"
        android:background="@drawable/backgroundbutton"
        android:layout_marginTop="30dp" />
</LinearLayout>

ScrollViewにあるLinearLayoutに要素を追加した後。
解決策はありますか?
ありがとう。

4

2 に答える 2

10

次のことを試してください。

android:layout_height="0dp"
android:layout_weight="1"

これにより、ScrollViewは、他の要素によって占有されていない残りのスペースをすべて使用するようになります。

于 2012-08-26T14:16:12.323 に答える
1

あなたはandroid:layout_height="wrap_content"あなたの身長として持っていました。つまり、高さはその中のコンテンツと同じくらい高いということです。あなたがそれを全体の場所に置きたくない場合は、それに重みを与えることができます(上記の答えのように)、またはあなたはdpであなたの高さを設定することができます。例えば:

<LinearLayout
android:id="@+id/linearLayout1"
android:layout_width="fill_parent"
android:layout_marginLeft="50dp"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:layout_centerVertical="true"
android:orientation="vertical"
android:focusable="true"
android:focusableInTouchMode="true"
android:background="@drawable/linearlayoutbackground"
android:weightSum="1.5" >

<TextView
    android:layout_width="wrap_content"
    android:layout_height="0dp"
    android:layout_weight = "0.2"
    android:text="@string/nom_des_joueurs"
    android:textAppearance="?android:attr/textAppearanceLarge"
    android:layout_marginBottom="30dp" />

<ScrollView
    android:id="@+id/scrollView1"
    android:layout_width="match_parent"
    android:layout_height="0dp"
    android:layout_weight = "1">

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

    </LinearLayout>

</ScrollView>

<Button
    android:id="@+id/okPlayersName"
    android:layout_width="match_parent"
    android:layout_height="0"
    android:layout_weight = "0.3">
    android:text="@string/ok"
    android:background="@drawable/backgroundbutton"
    android:layout_marginTop="30dp" />

ご覧のとおり、線形レイアウトに「合計」を指定すると、彼のすべての子に重みが与えられます。はっきりしていますか?それはあなたが必要なものですか?

于 2012-08-26T14:30:27.530 に答える