我需要创建一个 Map,其中键是类,值是适当类的对象。
喜欢:
mapOf<KClass<T>, T>(
Int::class to 10,
String::class to "Ten"
)
Run Code Online (Sandbox Code Playgroud)
我想使用泛型来避免“无效”条目,例如 Int::class to "Ten"
我该如何实施?
我使用断点,它在调试控制台(而不是logcat!)中生成消息.不幸的是,调试控制台还包含很多其他消息,例如吨
D/Surface:Surface :: setBuffersDimensions(this = 0xb45d4700,w = 720,h = 1280)
如何只留下断点的消息?
我制作了一个没有任何内容视图的启动屏幕(仅使用徽标图像作为主题背景),该屏幕一直显示到应用程序初始化完成。
如果在初始化期间发生错误,我想通过小吃栏通知用户。有没有一种方法可以在不膨胀内容视图的情况下显示小吃栏?
我试图将getWindow().getDecorView()其作为view参数传递给Snackbar.make(),但什么也没发生。
我创建了这样的布局
<?xml version="1.0" encoding="utf-8"?>
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent">
<android.support.constraint.ConstraintLayout
android:layout_width="match_parent"
android:layout_height="wrap_content">
<TextView
android:id="@+id/top"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:background="@color/gray"
android:gravity="center"
android:padding="10dp"
android:text="top"
android:textColor="@color/white"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
<TextView
android:id="@+id/middle"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:background="@color/green"
android:gravity="center"
android:minHeight="300dp"
android:padding="10dp"
android:text="middle"
android:textColor="@color/white"
app:layout_constraintBottom_toTopOf="@id/bottom"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@id/top" />
<TextView
android:id="@+id/bottom"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:background="@color/gray"
android:gravity="center"
android:padding="10dp"
android:text="bottom"
android:textColor="@color/white"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent" />
</android.support.constraint.ConstraintLayout>
Run Code Online (Sandbox Code Playgroud)
它确实按预期在小屏幕上滚动。但在较大的屏幕上,它会在下方留下空间

如何使布局匹配屏幕高度,但仍然可以在小屏幕上滚动?
尝试将“中间”高度设置为 0dp,但这没有帮助。
添加android:fillViewport="true"并ScrollView设置中间的高度可以0dp解决空间问题,但会带来滚动问题 - 在小屏幕上,中间会缩小,而不是滚动。