如何制作具有实际全屏功能的应用程序,其中的布局要在缺口下方呈现?
这就是我想要的:
这是我尝试过的代码:
class MainActivity : Activity() {
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_main)
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.P) {
// window.addFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN)
val attrib = window.attributes
attrib.layoutInDisplayCutoutMode = WindowManager.LayoutParams.LAYOUT_IN_DISPLAY_CUTOUT_MODE_ALWAYS
layout_main.setOnApplyWindowInsetsListener { _, windowInsets ->
val inset = windowInsets.displayCutout
Log.d("Tag", "Inset: $inset")
windowInsets
}
}
}
}
Run Code Online (Sandbox Code Playgroud)
布局:
<?xml version="1.0" encoding="utf-8"?>
<android.support.constraint.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="@+id/layout_main"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#3000FFFF"
android:fitsSystemWindows="true">
<View
android:layout_width="50dp"
android:layout_height="50dp"
android:background="#FFFF0000"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
<View
android:layout_width="50dp"
android:layout_height="50dp"
android:background="#FF00FF00"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintTop_toTopOf="parent" />
<View
android:layout_width="50dp"
android:layout_height="50dp"
android:background="#FF0000FF"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintStart_toStartOf="parent" />
<View …Run Code Online (Sandbox Code Playgroud) 您如何显示一侧(水平/垂直)非常大的项目列表,并允许它自由滚动/拖动 - 就像 Google 表格一样?
我试过使用 aNestedScrollView和 a RecyclerView,但一次只能向一个方向滚动,我需要它能够自由拖动(不需要捏/缩放功能,但如果可以做到,它是一个奖金)。
这是我尝试过的 GIF,它有效,但绝对不是我想要的。
这是布局文件:
<?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">
<include
layout="@layout/include_toolbar"
android:id="@+id/toolbar" />
<android.support.v4.widget.NestedScrollView
android:layout_width="match_parent"
android:layout_height="match_parent">
<android.support.v7.widget.RecyclerView
android:id="@+id/recycler_biscroll"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
</android.support.v4.widget.NestedScrollView>
</LinearLayout>
Run Code Online (Sandbox Code Playgroud) android android-scrollview android-scroll android-recyclerview android-scrolling
android ×2