草庐IT

android - 在 Bottom Sheet 中向下滚动

coder 2023-12-01 原文

我想在 Bottom Sheet 完全向上(向上拖动到完整屏幕)时向下 ScrollView 。向上滚动时效果很好,但向下滚动时不起作用。相反,整个底板都掉下来了。有出路吗?

主要 Activity

import android.os.Bundle;
import android.support.design.widget.BottomSheetBehavior;
import android.support.design.widget.BottomSheetDialog;
import android.support.design.widget.FloatingActionButton;
import android.support.design.widget.Snackbar;
import android.support.v7.app.AppCompatActivity;
import android.support.v7.widget.Toolbar;
import android.util.TypedValue;
import android.view.View;
import android.view.Menu;
import android.view.MenuItem;
import android.widget.Button;

public class MainActivity extends AppCompatActivity {
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        Button fab = (Button) findViewById(R.id.button);
        fab.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                BottomSheetDialog bottomSheetDialog  = new BottomSheetDialog(MainActivity.this);
                View parentView = getLayoutInflater().inflate(R.layout.sheetlayout,null);
                bottomSheetDialog.setContentView(parentView);
                BottomSheetBehavior bottomSheetBehavior = BottomSheetBehavior.from((View) parentView.getParent());
                bottomSheetBehavior.setPeekHeight(
                        (int) TypedValue.applyDimension(
                                TypedValue.COMPLEX_UNIT_DIP,100,getResources().getDisplayMetrics()
                        )
                );
                bottomSheetDialog.show();

            }
        });
    }
}

SheetLayout.xml

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    <Button
        android:text="button18"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:id="@+id/button6" />
</LinearLayout>
    </ScrollView>

编辑1

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


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

<android.support.design.widget.CoordinatorLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:orientation="vertical" android:layout_width="match_parent"
    android:layout_height="match_parent"
    >

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

        <Button
            android:text="button18"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:id="@+id/button6" />
    </LinearLayout>
</android.support.design.widget.CoordinatorLayout>
    </ScrollView>

编辑2

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

<android.support.design.widget.CoordinatorLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:orientation="vertical"
    android:layout_width="match_parent"
    android:layout_height="match_parent">

    <ScrollView
        android:layout_width="match_parent"
        app:layout_behavior="android.support.design.widget.BottomSheetBehavior"
        android:layout_height="match_parent">

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

        <Button
            android:text="@string/button1"
            android:layout_width="match_parent"
            android:layout_height="0dp"
            android:id="@+id/button1"
            android:layout_weight="0.66" />

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

        <Button
            android:text="button18"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:id="@+id/button6" />
    </LinearLayout>
    </ScrollView>
</android.support.design.widget.CoordinatorLayout>

最佳答案

我遇到了同样的问题并使用 android.support.v4.widget.NestedScrollView 修复了它。下面是我的 Bottom Sheet 布局代码

<?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"
    android:paddingBottom="8dp"
    android:paddingTop="8dp">
    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:clickable="true"
        android:foreground="?attr/selectableItemBackground"
        android:orientation="horizontal"
        android:paddingBottom="8dp"
        android:paddingLeft="@dimen/activity_margin"
        android:paddingRight="@dimen/activity_margin"
        android:paddingTop="8dp">

        <ImageView
            android:layout_width="24dp"
            android:layout_height="24dp"
            android:layout_marginRight="32dp"
            android:src="@drawable/ic_email_black_24dp"
            android:tint="#737373" />

        <TextView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_gravity="center_vertical"
            android:text="Email a Copy"
            android:textColor="#737373"
            android:textSize="16sp" />

    </LinearLayout>

    <android.support.v4.widget.NestedScrollView
        android:layout_width="match_parent"
        android:layout_height="match_parent">

        <WebView
            android:id="@+id/webpage"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:background="@color/colorPrimary"></WebView>
    </android.support.v4.widget.NestedScrollView>
</LinearLayout>

关于android - 在 Bottom Sheet 中向下滚动,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40357490/

有关android - 在 Bottom Sheet 中向下滚动的更多相关文章

  1. 安卓apk修改(Android反编译apk) - 2

    最近因为项目需要,需要将Android手机系统自带的某个系统软件反编译并更改里面某个资源,并重新打包,签名生成新的自定义的apk,下面我来介绍一下我的实现过程。APK修改,分为以下几步:反编译解包,修改,重打包,修改签名等步骤。安卓apk修改准备工作1.系统配置好JavaJDK环境变量2.需要root权限的手机(针对系统自带apk,其他软件免root)3.Auto-Sign签名工具4.apktool工具安卓apk修改开始反编译本文拿Android系统里面的Settings.apk做demo,具体如何将apk获取出来在此就不过多介绍了,直接进入主题:按键win+R输入cmd,打开命令窗口,并将路

  2. ruby - 绕过 Element 的方法无法滚动到 View 中 - Watir-webdriver with Ruby - 2

    因此,我们的页面中有以下代码:OnOff这是2个单选按钮。'开和关'。“关闭”是默认值。使用Watir-webdriver和Ruby,我们想要选择“打开”单选按钮。我们这样做:browser.radio(:id=>"HasRegistration_true").set但在这样做时,我们得到以下错误:`WebElement.clickElement':Elementcannotbescrolledintoview:[objectHTMLInputElement](Selenium::WebDriver::Error::MoveTargetOutOfBoundsError)我们知道Sele

  3. ruby - 为什么在 Ruby 中除法后负数会向下舍入? - 2

    我正在查看有关divmod的文档.下面显示了方法div、divmod、modulo和remainder之间差异的部分表格:为什么13.div(-4)四舍五入为-4而不是-3?Ruby中是否有向下舍入负数的规则或约定?如果是这样,为什么下面的代码没有向下舍入?-3.25.round()#3 最佳答案 13.div(-4)==-4和13.modulo(-4)==-3这样(-4*-4)+-3==13你得到了一致的关系(b*(a/b))+a.modulo(b)==aWhyis13.div(-4)roundedto-4andnotto-3?这

  4. 《计算机网络-自顶向下》04. 网络层-数据平面 - 2

    文章目录网络层数据平面和控制平面两者的概述数据平面控制平面控制平面:传统方法控制平面:SDN方法网络服务模型路由器工作原理通用路由器体系结构输入端口的功能基于目标的转发交换结构内存交换方式总线交换方式纵横式交换方式输出端口的功能何时何处出现缓存队列输入排队输出排队分组调度先进先出优先权排队循环和加权公平排队网络协议:PIv4、寻址、IPv6以及其它IPv4数据报格式IPv4数据报分片IPv4编址IP和子网掩码CIDR分类网络特殊地址分配地址获取一块地址(用于组织的子网内)获取主机地址:动态主机配置协议网络地址转换——NAT一些术语通用转发和SDN匹配动作参考资料网络层从表面上看网络层的作用:将

  5. Android Studio开发之使用内容组件Content获取通讯信息讲解及实战(附源码 包括添加手机联系人和发短信) - 2

    运行有问题或需要源码请点赞关注收藏后评论区留言一、利用ContentResolver读写联系人在实际开发中,普通App很少会开放数据接口给其他应用访问。内容组件能够派上用场的情况往往是App想要访问系统应用的通讯数据,比如查看联系人,短信,通话记录等等,以及对这些通讯数据及逆行增删改查。首先要给AndroidMaifest.xml中添加响应的权限配置 下面是往手机通讯录添加联系人信息的例子效果如下分成三个步骤先查出联系人的基本信息,然后查询联系人号码,再查询联系人邮箱代码 ContactAddActivity类packagecom.example.chapter07;importandroid

  6. Android 10.0 设置默认launcher后安装另外launcher后默认Launcher失效的功能修复 - 2

    1.前言 在10.0的系统rom定制化开发中,在系统中有多个launcher的时候,会在开机进入launcher的时候弹窗launcher列表,让用户选择进入哪个launcher,这样显得特别的不方便所以产品开发中,要求用RoleManager的相关api来设置默认Launcher,但是在设置完默认Launcher以后,在安装一款Launcher的时候,默认Launcher就会失效,在系统设置的默认应用中Launcher选项就为空,点击home键的时候会弹出默认Launcher列表,让选择进入哪个默认Launcher.所以需要从安装Launcher的流程来分析相关的设置。来解决问题设置默认La

  7. AiBote 2022 新研发的自动化框架,支持 Android 和 Windows 系统。速度非常快 - 2

    Ai-Bot基于流行的Node.js和JavaScript语言的一款新自动化框架,支持Windows和Android自动化。1、Windowsxpath元素定位算法支持支持Windows应用、.NET、WPF、Qt、Java和Electron客户端程序和ie、edgechrome浏览器2、Android支持原生APP和H5界面,元素定位速度是appium十倍,无线远程自动化操作多台安卓设备3、基于opencv图色算法,支持找图和多点找色,1080*2340全分辨率找图50MS以内4、内置免费OCR人工智能技术,无限制获取图片文字和找字功能。5、框架协议开源,除官方node.jsSDK外,用户可

  8. Android Gradle 7.1+新版本依赖变化 - 2

    前一段时间由于工作需要把可爱的小雪狐舍弃了,找到了小蜜蜂。但是新版本的小蜜蜂出现了很多和旧版本不一样的位置。1.功能位置迁移,原来在工程build.gradle的buildscript和allprojects移动至setting.gradle并改名为pluginManagement和dependencyResolutionManagement。里面的东西依旧可以按照原来的copy过来。pluginManagement{repositories{gradlePluginPortal()google()mavenCentral()}}dependencyResolutionManagement{r

  9. ruby - Ruboto 的最佳教程(适用于 Android 的 ruby​​)? - 2

    关闭。这个问题不符合StackOverflowguidelines.它目前不接受答案。要求我们推荐或查找工具、库或最喜欢的场外资源的问题对于StackOverflow来说是偏离主题的,因为它们往往会吸引自以为是的答案和垃圾邮件。相反,describetheproblem以及迄今为止为解决该问题所做的工作。关闭9年前。Improvethisquestion我几乎用完了Ruby,但现在想试试Ruboto,android上的ruby​​。谷歌未能给我足够的(几乎没有结果)。所以任何人都可以分享一些关于Ruboto的教程。

  10. Android Studio 解决Could not resolve com.android.tools.build:gradle:7.4.2问题 - 2

    Aproblemoccurredconfiguringrootproject'MyApplication2'.>Couldnotresolveallfilesforconfiguration':classpath'.  >Couldnotresolvecom.android.tools.build:gradle:7.4.2.   Requiredby:     project:>com.android.application:com.android.application.gradle.plugin:7.4.2     project:>com.android.library:com.andr

随机推荐