android - 持久性 BottomSheet : Swipe to Expand Issue

标签 android processing android-coordinatorlayout bottom-sheet material-components

我有一个 CoordinatorLayout,包括一个 LinearLayout 作为我的 BottomSheet。还有一个 FrameLayout(也是 CoordinatorLayout 的直接子级)。

<?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"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    tools:context=".MainActivity">

<FrameLayout
    android:id="@+id/sketchViewGroup"
    android:layout_width="match_parent"
    android:layout_height="match_parent" />

<LinearLayout
    android:id="@+id/bottomSheet"
    android:layout_width="match_parent"
    android:layout_height="340dp"
    android:background="@drawable/rounded_top"
    android:backgroundTint="@color/colorBottomSheetBackground"
    android:orientation="vertical"
    app:behavior_hideable="false"
    app:behavior_peekHeight="@dimen/bottomSheetPeekHeight"
    app:layout_behavior="android.support.design.widget.BottomSheetBehavior">

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="@dimen/bottomSheetPeekHeight"
        android:gravity="center_vertical"
        android:orientation="horizontal">

        <SeekBar
            android:id="@+id/fixedPointsSeekBar"
            style="@style/Widget.AppCompat.SeekBar.Discrete"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_marginStart="16dp"
            android:layout_marginEnd="16dp"
            android:max="10"
            android:progress="10" />

    </LinearLayout>
</LinearLayout>

我使用 Processing.jar 库在 FrameLayout 上绘制内容。

为此,我创建了一个 fragment (在 Processing 中称为 PFragement)并通过 SupportFragmentManager 将其添加到 FrameLayout。 PFragment 将 PApplet 作为构造函数。在 PApplet 中, Canvas 绘制发生,并且 widthheight 也被定义。此外,我调整了 PApplet 的大小以填充我的 FrameLayout。

class MainActivity : AppCompatActivity() {

    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        setContentView(R.layout.activity_main)

        val sketch = Sketch();

        sketchViewGroup.post {
            sketch.sketchWidth = sketchViewGroup.width 
            sketch.sketchHeight = sketchViewGroup.height
            // this works:
            // sketch.sketchWidth = sketchViewGroup.width -1
            // sketch.sketchHeight = sketchViewGroup.height -1 
            supportFragmentManager.beginTransaction().add(sketchViewGroup.id, PFragment(sketch)).commit();
        }
    }
}

public class Sketch extends PApplet {

    int sketchWidth = 100;
    int sketchHeight = 100;

    public void settings() {
        size(sketchWidth, sketchHeight);
    }

    public void setup(){
        background(0);
    }
}

现在,有线的事情正在发生:当我将 Sketch 的大小调整到与我的 FrameLayout 的大小完全相同时,我的 BottomSheet 不再正确扩展。但是,如果我减去草图的大小之一,一切都会按预期进行。有人可以解释一下并告诉您如何解决这个问题吗?

sketch.sketchWidth = sketchViewGroup.width 
sketch.sketchHeight = sketchViewGroup.height

enter image description here

sketch.sketchWidth = sketchViewGroup.width -1
sketch.sketchHeight = sketchViewGroup.height -1 

enter image description here

最佳答案

看起来您的 View 组的高度是 MATCH_PARENT,即 -1。当您从中减去 1 时,您会得到 -2,它等于 WRAP_CONTENT。所以我认为您只是将草图对象的高度设置为 WRAP_CONTENT

关于android - 持久性 BottomSheet : Swipe to Expand Issue,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54100305/

相关文章:

Android Activity 返回堆栈导航问题

android - 从 SQLite 数据库中获取日期和时间字符串并设置 AlarmManager

android - Android应用程序的自签名证书到期

android - 显示弹出窗口时更改背景颜色

java - 处理中的文本质量

linux - 在 Java 中启动 Shell 脚本并在退出时销毁所有进程

java - 是否可以修改 OSCeleton 发送lost_user 事件/消息的时间?

java - 主题错误 - 如何修复?

android - 隐藏工具栏时无法启用 webview 的滚动行为

android - 在 CoordinatorLayout 中平移谷歌地图导致 recyclerview 在 android 设计支持库 23.0.1 中滚动