如何在 ScrollView 内的 LinearLayout 底部放置按钮

     2023-04-18     205

关键词:

【中文标题】如何在 ScrollView 内的 LinearLayout 底部放置按钮【英文标题】:How to place button at the bottom of LinearLayout within a ScrollView 【发布时间】:2020-11-09 08:40:51 【问题描述】:

我创建了一个 addview (xml)。当我按下添加按钮时,它会在 LinearLayout 中创建一个新按钮。添加按钮放置在同一个线性布局中。但是当我放置添加按钮时,它保持在相同的位置。但我希望按钮位于添加视图的底部。这是我的 xml。

    <ScrollView
    android:layout_
    android:layout_
    android:layout_below="@+id/banner"
    android:layout_above="@+id/linearmenu"
    android:layout_centerHorizontal="true">

    <LinearLayout
        android:id="@+id/linearLayout_addhere"
        android:layout_
        android:layout_gravity="top"
        android:layout_
        android:orientation="vertical" >

        <Button
            android:id="@+id/buttonAdd"
            android:layout_
            android:layout_
            android:layout_gravity="center"
            android:layout_marginTop="10dp"
            android:background="@drawable/add_button_design"
            android:drawableRight="@drawable/ic_add_white"
            android:paddingHorizontal="7dp"
            android:text="추가"
            android:textColor="#FFFFFF"
            android:textSize="18sp"
            app:layout_constraintEnd_toEndOf="parent"
            app:layout_constraintHorizontal_bias="0.5"
            app:layout_constraintStart_toStartOf="parent" />


    </LinearLayout>

</ScrollView>

【问题讨论】:

【参考方案1】:

使用 LinearLayout

试试这种方式
<?xml version="1.0" encoding="utf-8"?>
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_
    android:layout_
    android:layout_above="@+id/linearmenu"
    android:layout_below="@+id/banner"
    android:layout_centerHorizontal="true"
    android:fillViewport="true">

    <LinearLayout
        android:layout_
        android:layout_
        android:orientation="vertical">

        <LinearLayout
            android:id="@+id/linearLayout_addhere"
            android:layout_
            android:layout_
            android:orientation="vertical"
            android:layout_weight="1">

        </LinearLayout>

        <Button
            android:id="@+id/buttonAdd"
            android:layout_
            android:layout_
            android:layout_gravity="bottom"
            android:layout_marginTop="10dp"
            android:paddingHorizontal="7dp"
            android:text="추가"
            android:textColor="#FFFFFF"
            android:textSize="18sp" />


    </LinearLayout>

</ScrollView>

使用 RelativeLayout

试试这种方式

<RelativeLayout
    android:layout_
    android:layout_
    android:orientation="vertical">
    

    <Button
        android:id="@+id/buttonAdd"
        android:layout_
        android:layout_
        android:layout_gravity="bottom"
        android:layout_marginTop="10dp"
        android:layout_alignParentBottom="true"
        android:paddingHorizontal="7dp"
        android:text="추가"
        android:textColor="#FFFFFF"
        android:textSize="18sp" />


</RelativeLayout>

使用 ConstraintLayout

试试这种方式
<?xml version="1.0" encoding="utf-8"?>
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_
    android:layout_
    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:layout_above="@+id/linearmenu"
    android:layout_below="@+id/banner"
    android:layout_centerHorizontal="true"
    android:fillViewport="true">

    <androidx.constraintlayout.widget.ConstraintLayout
        android:layout_
        android:layout_
        android:orientation="vertical">


        <Button
            app:layout_constraintLeft_toLeftOf="parent"
            app:layout_constraintRight_toRightOf="parent"
            app:layout_constraintBottom_toBottomOf="parent"
            android:id="@+id/buttonAdd"
            android:layout_
            android:layout_
            android:layout_gravity="bottom"
            android:layout_marginTop="10dp"
            android:layout_alignParentBottom="true"
            android:paddingHorizontal="7dp"
            android:text="추가"
            android:textColor="#FFFFFF"
            android:textSize="18sp" />


    </androidx.constraintlayout.widget.ConstraintLayout>

</ScrollView>

【讨论】:

基维。 GridLayout 在 ScrollView 内的位置

】基维。GridLayout在ScrollView内的位置【英文标题】:Kivy.PositionofGridLayoutinsideScrollView【发布时间】:2019-08-1615:46:54【问题描述】:我放弃了。我想我已经尽力了。我需要一些解释如何定位嵌套布局类。在下面的代码中,我需要将... 查看详情

如何从 ScrollView 内的 RecyclerView 中移除焦点?

】如何从ScrollView内的RecyclerView中移除焦点?【英文标题】:HowtoremovefocusfromRecyclerViewinsideScrollView?【发布时间】:2016-10-1711:03:33【问题描述】:我有一个包含ImageView和RecyclerView的Scrollview。如果导航抽屉打开然后关闭RecyclerView自动... 查看详情

Android:如何检查 ScrollView 内的 View 是不是可见?

】Android:如何检查ScrollView内的View是不是可见?【英文标题】:Android:howtocheckifaViewinsideofScrollViewisvisible?Android:如何检查ScrollView内的View是否可见?【发布时间】:2011-06-0510:54:48【问题描述】:我有一个ScrollView,其中包含一系列... 查看详情

如何从 ScrollView 内的自定义组件中使用 prepareForSegue?

】如何从ScrollView内的自定义组件中使用prepareForSegue?【英文标题】:HowtouseprepareForSeguefrominsideacustomcomponentthatisinsideaScrollView?【发布时间】:2015-09-2809:41:40【问题描述】:我有一个自定义组件(带有自己的控制器和自己的xib),... 查看详情

在 scrollView 内的 contentView 上设置约束

】在scrollView内的contentView上设置约束【英文标题】:settingconstraintsoncontentViewinsidescrollView【发布时间】:2015-09-1806:25:22【问题描述】:对于我的项目,我需要制作一个距顶部64pt高度的自定义菜单。因此,默认导航栏可见性设置为... 查看详情

在 CollectionViewCell 内的 ScrollView 内缩放 UIImage [重复]

】在CollectionViewCell内的ScrollView内缩放UIImage[重复]【英文标题】:ZoomedUIImageinsideScrollViewinsideCollectionViewCell[duplicate]【发布时间】:2016-02-2114:23:50【问题描述】:我的目标是创建类似ApplePhotos应用程序的应用程序-显示照片、允许缩... 查看详情

ScrollView 内的 TableView

】ScrollView内的TableView【英文标题】:TableViewinsideScrollView【发布时间】:2010-12-2213:05:21【问题描述】:我想要在横向模式下的iPad的scrollView[0,0,1024,1400]中的tableView[50,50,200,300]。ScrollView滚动良好,因为scrollView中的表格视图不需要触... 查看详情

TouchableOpacity 内的 ScrollView

】TouchableOpacity内的ScrollView【英文标题】:ScrollViewinsideTouchableOpacity【发布时间】:2017-08-1822:28:24【问题描述】:我正在尝试在TouchableOpacity组件内设置水平ScrollView(出于必要的原因)。然而TouchableOpacity会覆盖任何水平滚动功能... 查看详情

ViewPager 中片段内的 ScrollView 内的 Horizo​​ntalListView

】ViewPager中片段内的ScrollView内的Horizo​​ntalListView【英文标题】:HorizontalListViewinsideaScrollViewwithinfragmentsinaViewPager【发布时间】:2015-05-2516:15:26【问题描述】:在我的应用程序中,我有一个场景,我必须在viewpager中显示不同的产... 查看详情

android: ScrollView 内的 RecyclerView

】android:ScrollView内的RecyclerView【英文标题】:android:RecyclerViewinsideaScrollView【发布时间】:2014-10-2008:58:38【问题描述】:我有一个RecyclerView包裹在一个LinearLayout中,它可以按预期完美运行。我可以看到RecyclerView中的所有数据都已... 查看详情

如何在表格视图 IOS 内的滚动视图中创建文本字段

...动视图中创建文本字段【英文标题】:HowtocreatetextfieldsinscrollviewinsideofatableviewIOS【发布时间】:2012-11-0119:36:32【问题描述】:我需要在原型单元格内的滚动视图中创建多个文本字段Scrollview和所有其他元素都有不同的标签当用户... 查看详情

SwiftUI中ScrollView底部对齐内的VStack

】SwiftUI中ScrollView底部对齐内的VStack【英文标题】:VStackinsideScrollViewbottomalignmentinSwiftUI【发布时间】:2019-09-1517:49:55【问题描述】:目前正在构建一个聊天应用程序,我需要在屏幕底部显示新消息。我还需要让消息与底部对齐。... 查看详情

使用swift在scrollview内的stackview中更改uibutton中的标题

】使用swift在scrollview内的stackview中更改uibutton中的标题【英文标题】:Changingtitleinuibuttoninstackviewinsidescrollviewusingswift【发布时间】:2021-02-1113:38:22【问题描述】:请您帮我解释一下为什么按钮标题的填充不起作用?我在下面的代... 查看详情

WatchOs 上不显示 ScrollView 内的列表

】WatchOs上不显示ScrollView内的列表【英文标题】:ListinsideScrollViewisnotdisplayedonWatchOs【发布时间】:2019-10-1104:20:37【问题描述】:我在滚动视图中有一个列表,它没有显示在图像和按钮下方。我还尝试将列表和其他项目放在VStack中... 查看详情

如何根据 UIScrollview 内的按钮框架大小水平滚动 UIScrollView

】如何根据UIScrollview内的按钮框架大小水平滚动UIScrollView【英文标题】:HowtoscrollaUIScrollViewhorizontallybasedonthebuttonsframesizeinsidetheUIScrollview【发布时间】:2014-01-0406:47:36【问题描述】:最初我需要在scrollView上添加一个默认按钮。然... 查看详情

将视图动态添加到 ScrollView 内的 RelativeLayout

】将视图动态添加到ScrollView内的RelativeLayout【英文标题】:DynamicallyaddingviewstoRelativeLayoutinsideScrollView【发布时间】:2012-04-1716:34:23【问题描述】:我正在尝试将动态创建的几个RelativeLayouts添加到一个LinearLayout中,该LinearLayout在一... 查看详情

ScrollView 内的 ColumnLayout 不会调整其内容的大小

】ScrollView内的ColumnLayout不会调整其内容的大小【英文标题】:ColumnLayoutinsideScrollViewdoesn\'tresizeitscontent【发布时间】:2020-10-2105:06:20【问题描述】:它的外观如下:第三个和第四个Card都用ColumnLayout布局。唯一的区别是第四个Card... 查看详情

导航控制器内的iOS ScrollView + Page Controller:如何更改每个页面的导航栏标题?

】导航控制器内的iOSScrollView+PageController:如何更改每个页面的导航栏标题?【英文标题】:iOSScrollView+PageControllerinsideNavigationController:HowtochangetitleoftheNavigationBarforeachpage?【发布时间】:2012-03-2317:51:43【问题描述】:在我的应用程... 查看详情