0

開発中のテスト プログラムに簡単なレイアウトを実装しました。画面には、ロゴ用の画像が 1 つだけあり、プログラムのタイトルを含む textView とボタンがあります。各要素を新しい行に配置したいので、線形レイアウトを使用しようとしています。私の場合、画像とテキストは非常に近いかもしれませんが、ボタンをページの下部に表示したいと考えています。私は自分が間違っていることを理解していません。また、「下」の値を持つボタンに android:layoutGravity プロパティを追加しましたが、何も変更されていません。これは私が使用しているコードです:

<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@drawable/background">

<LinearLayout 
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:paddingBottom="@dimen/activity_vertical_margin"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="0sp"
tools:context=".DiLand"
android:orientation="vertical" >

     <ImageView
         android:id="@+id/logo"
         android:layout_width="match_parent"
         android:layout_height="wrap_content"
         android:layout_marginTop="0sp"
         android:src="@drawable/logo2" />

     <TextView
        android:id="@+id/title"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:text="@string/titleApp"
        android:textColor="@color/titleColor"
        android:textSize="35sp"
        android:gravity="top"
        android:layout_marginTop="0sp"
        />

    <Button
        android:layout_width="140sp"
        android:layout_height="50sp"
        android:text="@string/startButton"
        android:id="@+id/start_button"
        android:background="@drawable/start_button"
        android:textColor="@color/whiteColor"
        android:textSize="30sp"
        android:layout_gravity="bottom"
    />

</LinearLayout>
</ScrollView>

手伝ってくれてありがとう!

4

4 に答える 4

1

その理由は、match_parent/の子のfill_parent高さScrollViewが無視されるためです。それが尊重された場合ScrollView、コンテンツとスクロール ビュー ウィンドウが同じ高さになるため、 は役に立たなくなります。

android:fillViewPort="true"に属性を設定ScrollViewして、ScrollView子が親の高さよりも小さい場合は親の高さまで拡張することができます。ScrollView子が親よりも背が高い場合、この属性は効果がありません。このようにして、スクロールするコンテンツにボタンを保持しながら、ボタンを常に下部に配置できます。

于 2013-09-13T10:27:45.667 に答える
1

以下を使用して、LinearLayout を RelativeLayout に変更します。

android:orientation="vertical"

そのため、レイアウトは引き続きすべてのビューで新しい行になり、ボタンに次を追加します。

android:layout_alignParentBottom="true"

このようにして、ボタンは画面/レイアウトの下部に配置されます。ScrollView の親が画面全体を埋めていることを確認してください。

編集: imageView に追加:

android:layout_above="@+id/title"

textView に追加します。

android:layout_above="@+id/start_button"
android:layout_below="@+id/logo"

ボタンに追加: android:layout_below="@+id/title"

今すぐ試して書いてください。

于 2013-09-13T10:02:30.230 に答える
0

それは LinearLayout であるため、すべての空間を割り当てるのではなく、順番にのみ割り当てます。以下のコードを試してください:

<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@drawable/background">

<LinearLayout 
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:paddingBottom="@dimen/activity_vertical_margin"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="0sp"
tools:context=".DiLand"
android:orientation="vertical" >

     <ImageView
         android:id="@+id/logo"
         android:layout_width="match_parent"
         android:layout_height="wrap_content"
         android:layout_marginTop="0sp"
         android:src="@drawable/logo2" />

     <TextView
        android:id="@+id/title"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:text="@string/titleApp"
        android:textColor="@color/titleColor"
        android:textSize="35sp"
        android:gravity="top"
        android:layout_marginTop="0sp"
        />

<View

android:layout_height="0dp"
android:layout_weight="1"
android:layout_width="match_parent">
</View>

    <Button
        android:layout_width="140sp"
        android:layout_height="50sp"
        android:text="@string/startButton"
        android:id="@+id/start_button"
        android:background="@drawable/start_button"
        android:textColor="@color/whiteColor"
        android:textSize="30sp"
        android:layout_gravity="bottom"
    />

</LinearLayout>
</ScrollView>
于 2013-09-13T09:59:22.987 に答える