16

上部に名前が表示されたシンプルなレイアウトと、画面の下部、またはさらにアイテムを追加する場合に備えてボタンを配置したいボタンがあります。

したがって、次のように LinearLayout で ScrollView を使用しています。

<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="@android:color/white"
android:fillViewport="true"
android:focusableInTouchMode="true"
android:paddingBottom="@dimen/activity_vertical_margin"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
tools:context=".ItemDetailActivity" >

<LinearLayout
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:orientation="vertical" >

    <!-- Name -->

    <RelativeLayout
        android:id="@+id/top_content"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_gravity="top" >

        <TextView
            android:id="@+id/name_label"
            style="@style/Header_Label_TextView"
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:text="@string/name" />

        <TextView
            android:id="@+id/name_value"
            style="@style/Value_Label_TextView"
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:layout_below="@id/name_label" />
    </RelativeLayout>

    <!-- button -->

    <RelativeLayout
        android:id="@+id/ButtonLayout"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:layout_gravity="bottom" >

        <Button
            android:id="@+id/add_button"
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:layout_marginTop="10sp"
            android:onClick="editItem"
            android:text="@string/button_edit" />
    </RelativeLayout>

    <requestFocus />
</LinearLayout>

これは私が得るものです:

レイアウト XML の結果

ボタンが画面の下部またはそれ以降に表示されるようにするにはどうすればよいですか。オンラインで検索すると、ほとんどの回答は「android:fillViewport="true"」を設定することでしたが、それは役に立ちません。私は何を間違っていますか?

4

4 に答える 4

1

スクロール ビューでは、LinearLayout の代わりに RelativeLayout を使用し、ボトム ビュー プロパティを設定します。

android:layout_alignParentBottom="true"
于 2016-04-26T09:58:59.487 に答える
0

LinearLayout (RelativeLayout よりもパフォーマンスが高い) を使用している場合は、次のようにandroid:gravity="bottom"&を設定する必要があります。android:layout_height="match_parent"

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

    <Button
        android:id="@+id/add_button"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_marginTop="10sp"
        android:onClick="editItem"
        android:text="@string/button_edit" />
</LinearLayout>

参考:https ://demonuts.com/android-fillviewport/

于 2020-01-27T21:04:41.640 に答える