DelayedConfirmationView is blank on Android Wear

北城余情 提交于 2019-12-25 07:36:09

问题


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

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() {
...

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>

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.

Any ideas?


回答1:


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

Part of main_activity.xml file:

    <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"

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);

But in addition they also invoke .start() method:

    delayedConfirmationView.start();


EDIT:

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"

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"

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:)



来源:https://stackoverflow.com/questions/24800263/delayedconfirmationview-is-blank-on-android-wear

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!