DelayedConfirmationView是Android Wear空白 [英] DelayedConfirmationView is blank on Android Wear

查看:243
本文介绍了DelayedConfirmationView是Android Wear空白的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图从支持库使用Andoird磨损的DelayedConfirmationView,通过启动一个活动。

I'm attempting to use Andoird Wear's DelayedConfirmationView from the support library, by starting an activity.

该活动有这OnCreate中:

The activity has this in OnCreate:

setContentView(R.layout.delayed_main);
mDelayed = (DelayedConfirmationView) findViewById(R.id.delay);
mDelayed.setTotalTimeMs(4000);
//mDelayed.setImageDrawable(getResources().getDrawable(R.drawable.close_button));
mDelayed.setListener(new DelayedConfirmationView.DelayedConfirmationListener() {
...

我delayed_main有这样的:

My delayed_main has this:

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    xmlns:app="http://schemas.android.com/apk/android.support.wearable.view"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    tools:context=".DelayedConfirmActivity">

<android.support.wearable.view.DelayedConfirmationView
    android:id="@+id/delay"
    app:circle_border_color="#2299ee"
    app:circle_border_width="5sp"
    app:circle_color="#222222"
    app:circle_padding="5sp"
    app:circle_radius="80sp"
    app:update_interval="100"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_centerHorizontal="true"
    android:layout_centerVertical="true" />
</RelativeLayout>

我没有得到任何的异常在我的OnCreate,但我得到的是一个空白屏幕。我试过setImageDrawable。也试过的setContentView(视图)传递新的DelayedConfirmationView实例。还试图删除所有应用程序:在属性上面XML(希望一些合理的默认值将适用)。该文档不给任何例子,以什么期望,或如何使用。

I get no exception in my OnCreate, but all I get is a blank white screen. I've tried setImageDrawable. Also tried setContentView(View) passing in a new DelayedConfirmationView instance. Also tried deleting all the app: attributes in the above XML (hoping that some sensible defaults will apply). The docs don't give any example as to what to expect, or how to use.

任何想法?

推荐答案

有在SDK示例项目名为 DelayedConfirmation 。如果你在你的SDK管理器下载示例 - 你可以找到,如果在这里: SDK \\ SAMPLES \\ Android的20 \\耐磨\\ DelayedConfirmation

There is a sample project in sdk called DelayedConfirmation. If you have samples downloaded in your SDK Manager - you can find if here: sdk\samples\android-20\wearable\DelayedConfirmation

main_activity.xml 文件的部分:

    <android.support.wearable.view.DelayedConfirmationView
        android:id="@+id/delayed_confirmation"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_gravity="center"
        android:src="@drawable/ic_launcher"
        app:circle_color="@color/blue"
        app:circle_radius="@dimen/circle_radius"
        app:circle_radius_pressed="@dimen/circle_radius_pressed"
        app:circle_padding="@dimen/circle_padding"
        app:circle_border_width="@dimen/circle_border_normal_width"
        app:circle_border_color="@color/white"/>

所以这里唯一的额外属性是:

so the only extra attribute here is:

    app:circle_radius_pressed="@dimen/circle_radius_pressed"

在MainActivity.java类有几乎相同的路线,你设置:

in MainActivity.java class there are almost the same lines as you set:

    delayedConfirmationView = (DelayedConfirmationView) findViewById(R.id.delayed_confirmation);
    delayedConfirmationView.setTotalTimeMs(NUM_SECONDS * 1000);
    ...
    delayedConfirmationView.setListener(this);

但除此之外,他们还调用。开始()方法:

    delayedConfirmationView.start();


编辑:

我测试过的 DelayedConfirmationView 只的FrameLayout和它工作得很好,所以BoxInsetLayout无关,在这里做。

即使复制和放大器后,粘贴 DelayedConfirmationView XML code一切也适用确定,浅灰色的圆圈按钮显示在屏幕上。所以,我很惊讶了一下:)




与此code打的多之后,我已经意识到,你有错的xmlns:应用程序行:


I've tested the DelayedConfirmationView with just FrameLayout and it works just fine, so BoxInsetLayout has nothing to do here.
Even after copy&paste your DelayedConfirmationView xml code everything also works OK, the grayish circle button is displayed on screen. So I was surprised a bit:)

After playing more with this code I've realized that you have wrong xmlns:app line:

xmlns:app="http://schemas.android.com/apk/android.support.wearable.view"

您不能指定库的包所在的属性是从(以同样的方式就像你不能使用 android.support.wearable.R 类 - 你需要使用ř从自己的包中的类,您需要使用:

You cannot specify the package of library where the attributes are from (the same way like you cannot use android.support.wearable.R class - You need to use R class from your own package. You need to use:

xmlns:app="http://schemas.android.com/apk/res-auto"

,然后一切工作,在你的code罚款。这就是为什么与复制 BoxInsetLayout code替换根视图后(适当的xmlns )的按钮, code已经开始工作了:)

and then everything work fine in your code. This is the reason why after replacing root view with copied BoxInsetLayout code (with proper xmlns) the button the code has started to work:)

这篇关于DelayedConfirmationView是Android Wear空白的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆