弯曲的滚动条和 BoxInsetLayout
Curved scrollbars and BoxInsetLayout
我创建了一个确认 activity 以获得用户同意以继续执行操作。我使用未弃用的 android.support.wear.widget.BoxInsetLayout 创建了 activity。
不幸的是,描述变得比屏幕可以显示的更长,并且按钮被截断并且无法向下滚动。我尝试添加一个 ScrollView 和一些滚动条属性,但我无法让它工作。
查看android磨损系统中的一些确认活动,确实可以得到带有弯曲滚动条的BoxInsetLayout。
如何使 BoxInsetLayout 在弯曲模式下可滚动?
我必须堆叠 WearableRecyclerView 和 BoxInsetLayout 吗?
期待您的回答。提前致谢!
图片:
活动布局xml:
<?xml version="1.0" encoding="utf-8"?>
<android.support.wear.widget.BoxInsetLayout
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:background="@color/dark_grey">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:gravity="center"
android:orientation="vertical"
app:boxedEdges="all">
<TextView
android:id="@+id/text_description"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginBottom="4dp"
android:fontFamily="sans-serif-condensed"
android:gravity="bottom|center"
android:text=""
android:textSize="14sp" />
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginBottom="4dp"
android:layout_marginTop="4dp"
android:fontFamily="sans-serif-condensed"
android:gravity="bottom|center"
android:text="@string/warning_question_colorful_ambient"
android:textSize="16sp" />
<FrameLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginBottom="4dp"
android:layout_marginTop="4dp">
<android.support.wearable.view.CircledImageView
android:id="@+id/button_cancel"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="start|end"
android:src="@drawable/ic_close_24dp"
app:circle_color="#AFAFAF"
app:circle_radius="25dp"
app:circle_radius_pressed="20dp" />
<android.support.wearable.view.CircledImageView
android:id="@+id/button_ok"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="end|bottom"
android:src="@drawable/ic_check_24dp"
app:circle_color="#0EB695"
app:circle_radius="25dp"
app:circle_radius_pressed="20dp" />
</FrameLayout>
</LinearLayout>
</android.support.wear.widget.BoxInsetLayout>
我找到了适合我的问题的解决方案:我废弃了 BoxInsetLayout。
似乎无法使此布局可滚动。
作为替代方案,我只是使用带有 LinearLayout 的 ScrollView 作为子视图。 ScrollView 本身支持弯曲的滚动条并支持圆形屏幕我自己计算插图并将其作为填充应用到 LinearLayout。
我写了一篇博客 post 关于这个具体问题和解决方案:https://www.journal.deviantdev.com/android-wear-scrollable-boxinsetlayout/
此外,我用解决方案制作了一个片段并将其上传到 Bitbucket:https://bitbucket.org/snippets/devdev-dev/keR67A
<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">
<LinearLayout
android:id="@+id/layout_content"
android:layout_width="match_parent"
android:layout_height="wrap_content">
[..]
</LinearLayout>
override fun onCreate(savedInstanceState: Bundle?) {
[..]
adjustInset()
}
private fun adjustInset() {
if (applicationContext.resources.configuration.isScreenRound) {
val inset = (FACTOR * displayMetrics.widthPixels).toInt()
layout_content.setPadding(inset, inset, inset, inset)
}
}
companion object {
private const val FACTOR = 0.146467f // c = a * sqrt(2)
}
我创建了一个确认 activity 以获得用户同意以继续执行操作。我使用未弃用的 android.support.wear.widget.BoxInsetLayout 创建了 activity。
不幸的是,描述变得比屏幕可以显示的更长,并且按钮被截断并且无法向下滚动。我尝试添加一个 ScrollView 和一些滚动条属性,但我无法让它工作。
查看android磨损系统中的一些确认活动,确实可以得到带有弯曲滚动条的BoxInsetLayout。
如何使 BoxInsetLayout 在弯曲模式下可滚动? 我必须堆叠 WearableRecyclerView 和 BoxInsetLayout 吗?
期待您的回答。提前致谢!
图片:
活动布局xml:
<?xml version="1.0" encoding="utf-8"?>
<android.support.wear.widget.BoxInsetLayout
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:background="@color/dark_grey">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:gravity="center"
android:orientation="vertical"
app:boxedEdges="all">
<TextView
android:id="@+id/text_description"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginBottom="4dp"
android:fontFamily="sans-serif-condensed"
android:gravity="bottom|center"
android:text=""
android:textSize="14sp" />
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginBottom="4dp"
android:layout_marginTop="4dp"
android:fontFamily="sans-serif-condensed"
android:gravity="bottom|center"
android:text="@string/warning_question_colorful_ambient"
android:textSize="16sp" />
<FrameLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginBottom="4dp"
android:layout_marginTop="4dp">
<android.support.wearable.view.CircledImageView
android:id="@+id/button_cancel"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="start|end"
android:src="@drawable/ic_close_24dp"
app:circle_color="#AFAFAF"
app:circle_radius="25dp"
app:circle_radius_pressed="20dp" />
<android.support.wearable.view.CircledImageView
android:id="@+id/button_ok"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="end|bottom"
android:src="@drawable/ic_check_24dp"
app:circle_color="#0EB695"
app:circle_radius="25dp"
app:circle_radius_pressed="20dp" />
</FrameLayout>
</LinearLayout>
</android.support.wear.widget.BoxInsetLayout>
我找到了适合我的问题的解决方案:我废弃了 BoxInsetLayout。 似乎无法使此布局可滚动。
作为替代方案,我只是使用带有 LinearLayout 的 ScrollView 作为子视图。 ScrollView 本身支持弯曲的滚动条并支持圆形屏幕我自己计算插图并将其作为填充应用到 LinearLayout。
我写了一篇博客 post 关于这个具体问题和解决方案:https://www.journal.deviantdev.com/android-wear-scrollable-boxinsetlayout/
此外,我用解决方案制作了一个片段并将其上传到 Bitbucket:https://bitbucket.org/snippets/devdev-dev/keR67A
<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">
<LinearLayout
android:id="@+id/layout_content"
android:layout_width="match_parent"
android:layout_height="wrap_content">
[..]
</LinearLayout>
override fun onCreate(savedInstanceState: Bundle?) {
[..]
adjustInset()
}
private fun adjustInset() {
if (applicationContext.resources.configuration.isScreenRound) {
val inset = (FACTOR * displayMetrics.widthPixels).toInt()
layout_content.setPadding(inset, inset, inset, inset)
}
}
companion object {
private const val FACTOR = 0.146467f // c = a * sqrt(2)
}