如何向整个活动添加滚动视图?(代码片段)

author author     2022-12-28     446

关键词:

我尝试在活动布局上的所有内容周围添加滚动视图,但它给了我一个错误,说它只能放在一件事上。

我的活动,有一个标题textview然后是一个图像,然后是一个描述文本视图,你无法阅读整个描述,因为它很长并且低于我的屏幕边缘。如何让whoel事物可滚动?

我的xml看起来像这样:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical" >


    <TextView
        android:id="@+id/beerTitle"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:ems="10"
        android:textSize="40sp"
        android:textStyle = "bold"
        >
    </TextView>

    <ImageView android:id="@+id/image"
        android:layout_height="wrap_content"
        android:layout_width="fill_parent"
        android:layout_margin="10dip"/>

    <Button
        android:id="@+id/buttonBrewery"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:text="" />
    <Button
        android:id="@+id/buttonStyle"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:text="" />

    <TextView
        android:id="@+id/beerDEscriptionTitle"
        android:textStyle = "bold"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:ems="10"
        android:textSize="20sp"
        android:text="Description"
        ></TextView>
    <TextView
        android:id="@+id/beerDescription"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:ems="10"
        android:textSize="15sp"

        ></TextView>

</LinearLayout>
答案

试试这个:

<?xml version="1.0" encoding="utf-8"?>
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent" >

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

        <!-- TextView and other stuff -->

    </LinearLayout>
</ScrollView>
另一答案

LinearLayout(高度为wrap_content)包裹SrollView(高度为fill_parent)。

另一答案

“一件事”是你的LinearLayout。只需将其包装在ScrollView中,您将封装整个活动的布局。

另外,如果你想在ScrollView中只包装一个elemtnet,你只需将该元素放在它自己的布局中,如线性或相对布局,然后它就成为你的ScrollView的一个元素。

另一答案

只是用这个

<?xml version="1.0" encoding="utf-8"?>
 <ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
        android:id="@+id/scrollview"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content">
<LinearLayout 
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical" >


    <TextView
        android:id="@+id/beerTitle"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:ems="10"
        android:textSize="40sp"
        android:textStyle = "bold"
        >
    </TextView>

    <ImageView android:id="@+id/image"
        android:layout_height="wrap_content"
        android:layout_width="fill_parent"
        android:layout_margin="10dip"/>

    <Button
        android:id="@+id/buttonBrewery"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:text="" />
    <Button
        android:id="@+id/buttonStyle"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:text="" />

    <TextView
        android:id="@+id/beerDEscriptionTitle"
        android:textStyle = "bold"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:ems="10"
        android:textSize="20sp"
        android:text="Description"
        ></TextView>
    <TextView
        android:id="@+id/beerDescription"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:ems="10"
        android:textSize="15sp"

        ></TextView>

</LinearLayout>
</ScrollView>

7.3qscrollarea滚动视图(代码片段)

...其子类)添加滚动视图。滚动视图可以在widget的尺寸超过整个框架的尺寸时,显示滚动条,显示滚动条之后子窗口的整个内容,都可以被用户看到。这个子窗口使用setWidget()函数指定。图7-3-1继承关系7.3.1QscrollArea滚动视图显示图... 查看详情

如何在不向用户显示视图的情况下捕获整个滚动视图的图片

】如何在不向用户显示视图的情况下捕获整个滚动视图的图片【英文标题】:Howtocapturepicturesofthewholescrollviewwithoutshowingtheviewtotheuser【发布时间】:2019-02-2712:08:45【问题描述】:我正在我的应用程序中实现打印功能,我希望将屏... 查看详情

如何向滚动视图添加渐变?

】如何向滚动视图添加渐变?【英文标题】:Howtoaddagradienttoascrollview?【发布时间】:2011-04-2016:54:55【问题描述】:我正在尝试向不同的UIScrollView和UITableView添加一堆渐变。我遇到的如何实现这一点的最常见示例来自MattGalagher的精... 查看详情

java示例代码_如何在片段中向滚动条添加两个按钮

java示例代码_如何在片段中向滚动条添加两个按钮 查看详情

Android studio - 如何将多个recyclerviews置于活动中并使屏幕可滚动?

】Androidstudio-如何将多个recyclerviews置于活动中并使屏幕可滚动?【英文标题】:Androidstudio-howtoputmultiplerecyclerviewsinactivityandmakethescreenscrollable?【发布时间】:2021-07-1710:13:49【问题描述】:我想向活动添加多个回收站视图,但屏幕... 查看详情

当设备向左或向右旋转时如何添加带有页面控件的滚动视图?

】当设备向左或向右旋转时如何添加带有页面控件的滚动视图?【英文标题】:Howaddscrollviewwithpagecontrolwhendevicerotatetoleftorright?【发布时间】:2011-11-1509:05:16【问题描述】:我正在设计一个应用程序,其中有一个表视图控制器。... 查看详情

向 UITableViewCells 添加子视图会导致滚动时出现问题

...发布时间】:2013-03-0316:15:06【问题描述】:我完全不知道如何解决这个问题。所以我有一个UITableView并且在委托方法cellForRowAtIndex:如果单元格为nil(表格视图的初始构建),我将向每个单元格添加几个 查看详情

如何通过向它们添加组件来使滚动器内的视图自动调整大小? - 斯威夫特 3

】如何通过向它们添加组件来使滚动器内的视图自动调整大小?-斯威夫特3【英文标题】:Howtomakeviewsinsidescrollersautomaticallyresizebyaddingcomponentstothem?-Swift3【发布时间】:2016-11-1413:53:56【问题描述】:我有一个滚动条,里面有一个... 查看详情

我希望整个活动都是可滚动的,但只有列表视图是可滚动的。我怎么做?

】我希望整个活动都是可滚动的,但只有列表视图是可滚动的。我怎么做?【英文标题】:Iwanttheentireactivitytobescrollablebutonlylistviewisscrollable.HowdoIdothat?【发布时间】:2019-01-0606:55:30【问题描述】:我从服务器将数据提取到我的list... 查看详情

如何从活动中更改片段中视图的可见性

】如何从活动中更改片段中视图的可见性【英文标题】:howtochangevisibilityaviewinafragmentfromtheactivity【发布时间】:2020-11-2114:49:13【问题描述】:如标题所述,?我的代码有一个启动活动和一个片段。我想从活动中更改片段内视图... 查看详情

如何制作可缩放的滚动视图?

】如何制作可缩放的滚动视图?【英文标题】:Howtomakezoomablescrollview?【发布时间】:2013-11-0602:21:03【问题描述】:在我的android应用程序中,我需要创建可缩放的活动。我找到了用于缩放线性布局here的有用代码。但是在我的应用... 查看详情

是否可以使滚动视图不覆盖整个屏幕?

我想知道是否有可能创建一个不覆盖整个iOS屏幕的ScrollView。我创造了一种我想象的视觉渲染。答案对的,这是可能的。将UIScrollView类用于滚动内容视图superview,并手动或使用autolayout将其放在视图控制器的根视图中。任何方法的... 查看详情

java为嵌套滚动视图添加更多分页(代码片段)

查看详情

Android:向活动添加片段

】Android:向活动添加片段【英文标题】:Android:Addingafragmenttoanactivity【发布时间】:2012-05-1207:00:20【问题描述】:我对Android还很陌生,所以这可能有一个明显的答案,但我似乎找不到。我正在编写一个计算器应用程序版本。我... 查看详情

如何在目标c中弹出popout整个视图?(代码片段)

我在ViewController中有四个视图作为iPad应用程序。每个视图都有一个不同的按钮和图表控制器。我需要在用户点击特定视图时弹出整个视图。我怎样才能实现这一目标呢?答案要以正确的方式执行此操作,我建议使用一点动画弹出... 查看详情

当新行添加到 UITextView 实例中时,如何向上滚动视图?

】当新行添加到UITextView实例中时,如何向上滚动视图?【英文标题】:HowtoscrollviewupasnewlineisaddedintoUITextViewinstance?【发布时间】:2011-10-2014:35:03【问题描述】:我已经成功设置了一个滚动视图,可以移动一些文本字段和一个文本... 查看详情

如何在整个屏幕上滚动表格视图

】如何在整个屏幕上滚动表格视图【英文标题】:Howtoscrolltableviewwiththewholescreen【发布时间】:2019-05-2115:59:47【问题描述】:我想在我的视图控制器中滚动并显示整个tableview。像这样,我希望collectionview在滚动时向上移动,tablevie... 查看详情

如何首先在活动中显示选定的视图

】如何首先在活动中显示选定的视图【英文标题】:HowtoshowselectedViewinanActivityfirst【发布时间】:2011-11-3017:31:18【问题描述】:我在AndroidTextView中有一个活动,然后ListView又是TextView。第一个TextView的内容填满了整个屏幕,为了查... 查看详情