我正在遵循 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>
这是卡片的截图:
谁能阐明为什么该属性没有按预期工作?
最佳答案
在 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/