我有一个 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 绘制发生,并且 width 和 height 也被定义。此外,我调整了 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
sketch.sketchWidth = sketchViewGroup.width -1
sketch.sketchHeight = sketchViewGroup.height -1
最佳答案
看起来您的 View 组的高度是 MATCH_PARENT
,即 -1
。当您从中减去 1 时,您会得到 -2
,它等于 WRAP_CONTENT
。所以我认为您只是将草图对象的高度设置为 WRAP_CONTENT
?
关于android - 持久性 BottomSheet : Swipe to Expand Issue,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54100305/