Android 对齐圆形磨损装置拐角处的元件
我正在尝试将一个对象对齐到圆形android wear设备的圆形_布局的一角。 正如你在这里看到的: 数字钟将被禁止使用 我在google IO 2014上看过android wear文档,有人展示了一行代码,以便正确对齐对象。 我希望数字时钟位于左上角,但不在屏幕外 有人有什么建议吗 以下是XML文件:Android 对齐圆形磨损装置拐角处的元件,android,android-layout,wear-os,Android,Android Layout,Wear Os,我正在尝试将一个对象对齐到圆形android wear设备的圆形_布局的一角。 正如你在这里看到的: 数字钟将被禁止使用 我在google IO 2014上看过android wear文档,有人展示了一行代码,以便正确对齐对象。 我希望数字时钟位于左上角,但不在屏幕外 有人有什么建议吗 以下是XML文件: <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MyActivity"
tools:deviceIds="wear_round">
<DigitalClock
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textColor="@color/text"
android:textSize="20sp"/>
</RelativeLayout>
文本视图超出了屏幕的范围。我监督了什么 根据Google IO 2014上显示的内容,您应该使用
BoxInsetLayout
:到目前为止,你只有这些吗?你有没有尝试过任何边距、填充或动态移动视图?我可以尝试添加填充或边距等,但我认为如果有其他方法会更容易。我肯定有,只是想知道是否有人熟悉它。@user2410644请告诉我下面的解决方案是否适用于您:)或者您在实现它时有任何问题吗?@MaciejCiemięga我编辑了我的帖子:它似乎不适用于我,我可能监督了一些事情?@user2410644我刚刚测试了这段代码,它工作正常。请看下面我的最新答案。如果此代码不适用于您,则表示您可能做错了什么。也许你正在“Android Wear Rect”系统上用“AndroidWearRound”模拟器皮肤测试它?请确保您在正确的仿真器配置中进行测试。“layout\u box”属性中的“box”不是有效值“what doYou needs to show me your xml layout more(例如,可能发布它)。还要确保已包含
xmlns:app=”http://schemas.android.com/apk/res-auto“
part.hmm似乎我的消费者认为它是一块方形手表,而它是圆形的。发生什么事?我认为这会影响我的预览。对于阅读本文的任何其他人来说,BoxInsetLayout
和WatchViewStub
必须是活动视图的根才能工作!我发现了困难的方法:(我撒谎!我的问题实际上是因为我的活动主题!只有少数几个主题可以与手表一起使用。(在sdk/platforms/android-20/data/res/values watch/themes\u device\u defaults.xml下)
<?xml version="1.0" encoding="utf-8"?>
<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">
<TextView android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="1234567890"
app:layout_box="top"/>
</android.support.wearable.view.BoxInsetLayout>
app:layout_box="top"
<?xml version="1.0" encoding="utf-8"?>
<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">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:background="@color/grey"
app:layout_box="top">
[...]
</LinearLayout>
</android.support.wearable.view.BoxInsetLayout>
<?xml version="1.0" encoding="utf-8"?>
<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">
<TextView android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="1234567890"
app:layout_box="all"/>
</android.support.wearable.view.BoxInsetLayout>
public class MainActivity extends Activity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
}
}