持续的BottomSheet:滑动即可扩大问题

时间:2019-01-08 21:55:20

标签: 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上绘制内容。

为此,我创建了一个片段(在处理中称为PFragement),并通过SupportFragmentManager将其添加到FrameLayout中。 PFragment将PApplet作为构造函数。在PApplet中进行画布绘制,并定义宽度高度。此外,我调整了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

1 个答案:

答案 0 :(得分:0)

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