ScrollView 和 LinearLayout 的困难

2024-05-14

我正在尝试制作一个 Android 布局:垂直 LinearLayout 内有 3 个组件。中心组件是一个ScrollView其中包含一个TextView。当。。。的时候TextView包含大量文本(超出了屏幕所能容纳的范围),ScrollView一直增长到屏幕底部,显示滚动条,并推送最后一个组件,aLinearLayout with a Button里面,屏幕外。

如果里面的文字TextView在 - 的里面ScrollView足够短,屏幕底部的按钮位置完美。

我想要实现的布局是:

我编写的布局的 XML 是:

<?xml version="1.0" encoding="UTF-8"?>

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

    <TextView android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:textColor="#FFFFFF"
            android:layout_marginLeft="10dip"
            android:layout_marginRight="10dip"
            android:layout_marginTop="10dip"
            android:layout_marginBottom="10dip"
            android:text="Title />

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

        <TextView android:id="@+id/text"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:autoLink="web"
                android:textColor="#FFFFFF"
                android:background="#444444"
                android:padding="10dip" />

    </ScrollView>

    <LinearLayout
            android:orientation="horizontal"
            android:layout_width="fill_parent"
            android:layout_height="fill_parent"
            android:layout_weight="1">

        <LinearLayout
                android:orientation="horizontal"
                android:layout_width="0dip"
                android:layout_height="wrap_content"
                android:layout_weight="1"/>

        <Button android:id="@+id/login_button"
                android:layout_width="0dip"
                android:layout_height="wrap_content"
                android:layout_gravity="bottom"
                android:layout_weight="1"
                android:text="@string/next_button"/>

    </LinearLayout>

</LinearLayout>

ScrollView是第二个视图对象,设置为wrap_content,比屏幕多。

我推荐一个相对布局。首先是顶部文本视图android:alignParentTop="true",底部 LinearLayout 接下来是android:alignParentBottom="true"以及 xml 中最后列出的滚动视图的值android:alignBelow="@id/whatYouCallTheHeader.

这将对齐屏幕底部的底部栏和顶部的标题,无论大小如何。然后,在放置页眉和页脚之后,滚动视图将有自己的位置。

本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

ScrollView 和 LinearLayout 的困难 的相关文章

随机推荐