按钮到屏幕底部

时间:2016-11-21 10:15:23

标签: android android-layout

我的布局看起来像这样,

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical">

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

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

            <include
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                layout="@layout/layout1" />

            <TextView
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:layout_weight="1"/>

            <Button
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:text="button"/>
        </LinearLayout>
    </ScrollView>
</LinearLayout>

我希望按钮显示在屏幕的底部,如果将其与活动一起使用,它可以正常工作。当我尝试使用片段虽然(在FrameLayout内)按钮根本不显示。任何建议?

修改

感谢您的回答,但我已经尝试了所有这些。让我澄清一下。我有一个包含ToolbarFramelayout的主要布局。使用FrameLayout对于我的4-5应用程序Fragments。其中一个已发布我之前发布的布局。

5 个答案:

答案 0 :(得分:1)

使用layout_weight

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical">

    <ScrollView
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_weight="1">

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

            <include
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                layout="@layout/layout1" />

            <TextView
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:layout_weight="1" />

        </LinearLayout>
    </ScrollView>

    <Button
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="button" />

</LinearLayout>

答案 1 :(得分:0)

尝试使用:

android:layout_gravity="bottom"

或:

android:layout_alignParentBottom="true"

在botton标签中。

答案 2 :(得分:0)

您需要为ScrollView设置属性

android:fillViewport="true"

并在按钮下面添加以下行

android:layout_alignParentBottom="true"
android:layout_gravity="center_horizontal"

我编辑了你的代码只是试试这个

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">

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

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

        <include
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            layout="@layout/layout1" />

        <TextView
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_weight="1"/>

        <Button
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_alignParentBottom="true"
            android:text="button"
            android:layout_gravity="center_horizontal" />

    </LinearLayout>
</ScrollView>

答案 3 :(得分:0)

你应该在这里使用ScrollView作为根布局而不是LinearLayout。

在scrollview中尝试此属性:

android:fillViewport="true"

可能会帮助你。

答案 4 :(得分:0)

tasgr86尝试这个代码希望这可以做一些想法或帮助..

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent">

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

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

        <include
            layout="@layout/layout1"
            android:layout_width="match_parent"
            android:layout_height="wrap_content" />

        <TextView
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_weight="1"
            android:text="Test" />

    </LinearLayout>
</ScrollView>

<Button
    android:id="@+id/button"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:layout_alignParentBottom="true"
    android:layout_marginBottom="5dp"
    android:text="button" />

</RelativeLayout>
相关问题