android - 无法将卡片与 Android Wear 底部对齐

标签 android wear-os

我正在遵循 Android 文档中的教程 here但他们没有按照我的期望去做。

我创建了一个 CardFrame 来在 watch 上显示一张卡片,并使用属性 app:layout_box="bottom" 让它出现在 watch 的底部,但正如您所看到的屏幕截图并非如此。这是我的 XML:

<android.support.wearable.view.BoxInsetLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:layout_height="match_parent"
    android:layout_width="match_parent">

    <android.support.wearable.view.CardScrollView
        android:id="@+id/card_scroll_view"
        android:layout_height="wrap_content"
        android:layout_width="match_parent"
        app:layout_box="bottom">

        <android.support.wearable.view.CardFrame
            android:layout_height="wrap_content"
            android:layout_width="match_parent">

            <LinearLayout
                android:layout_height="wrap_content"
                android:layout_width="match_parent"
                android:orientation="vertical"
                android:paddingLeft="5dp">
                <TextView
                    android:layout_height="wrap_content"
                    android:layout_width="match_parent"
                    android:text="Custom Title"
                    android:textColor="@color/black"
                    android:textSize="20sp"/>
                <TextView
                    android:layout_height="wrap_content"
                    android:layout_width="match_parent"
                    android:text="Custom Description"
                    android:textColor="@color/black"
                    android:textSize="14sp"/>
            </LinearLayout>
        </android.support.wearable.view.CardFrame>
    </android.support.wearable.view.CardScrollView>
</android.support.wearable.view.BoxInsetLayout>

这是卡片的截图:

enter image description here

谁能阐明为什么该属性没有按预期工作?

最佳答案

CardFrame 标签中添加属性 android:layout_gravity="bottom" ,如下所示:

<android.support.wearable.view.CardFrame
        android:layout_height="wrap_content"
        android:layout_width="match_parent"
        android:layout_gravity="bottom">

这解决了我的问题,卡片出现在底部。

解释: 我认为 cardframe 教程中属性“layout_box”的含义不是很清楚。来自 BoxInsetLayout docs ,似乎 layout_box="bottom"的意思是“确保 CardScrollView 的底部包含(或装箱)在 centre box 内”。这样可以防止卡的底部被裁掉。这并不意味着“在底部对齐”。 layout_gravity 属性将卡片放在底部。 layout_box 属性确保卡片内容的底部不会被裁剪掉。

关于android - 无法将卡片与 Android Wear 底部对齐,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35005844/

相关文章:

android - 添加文件夹 jniLibs 后 jniLibs 仍然无法工作

permissions - Android Wear 上请求权限

Android 精确闹钟总是关闭 3 分钟

android - 当有产品口味时,wear apk 不会部署

android - 为我的项目启用 Google Cloud Build API 时出错?

java - 有没有内置的图像识别功能

Android:联系人选择器 Intent |无法实例化 Uri 类型

java - 突出显示 TextView 中的文本行,包括所有宽度

android - Wear 模拟器显示手持 Activity 启动器类

android - 如何禁止我的应用程序出现在 Android Wear 设备上?