gpt4 book ai didi

android - ScrollView 和 LinearLayout 的困难

转载 作者:塔克拉玛干 更新时间:2023-11-02 08:29:49 25 4
gpt4 key购买 nike

我正在尝试制作一个 Android 布局:垂直 LinearLayout 内的 3 个组件。中心组件是一个包含 TextViewScrollView。当 TextView 包含大量文本(超出屏幕所能容纳的范围)时,ScrollView 会一直增长到屏幕底部,显示滚动条,并且将最后一个组件,一个带有 ButtonLinearLayout 推离屏幕。

如果 ScrollView 内的 TextView 内的文本足够短,则屏幕底部的按钮位置完美。

我要实现的布局是:

我编写的布局的 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是第二个view对象,设置为wrap_content,比screen多。

我推荐 RelativeLayout。顶部的 textview 首先是 android:alignParentTop="true",底部的 LinearLayout 接下来是 android:alignParentBottom="true",最后在 xml 中列出的 ScrollView 的值为 android:alignBelow="@id/whatYouCallTheHeader

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

关于android - ScrollView 和 LinearLayout 的困难,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7297601/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com