android wearOs开发

CircularProgressLayout

    • 布局
    • 代码

android wearOs开发_第1张图片

布局

<?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/res-auto"
    android:id="@+id/recycler_launcher_view"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:scrollbars="vertical">
    <androidx.wear.widget.CircularProgressLayout
        android:id="@+id/circular_progress"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_centerInParent="true"
        android:padding="4dp"
        app:backgroundColor="@color/blue_a400"
        app:colorSchemeColors="@color/red_a200"
        app:strokeWidth="4dp">
        <ImageView
            android:id="@+id/image_view"
            android:src="@drawable/a"
            android:layout_width="40dp"
            android:layout_height="40dp" />
    </androidx.wear.widget.CircularProgressLayout>
</RelativeLayout>

代码

package com.chery.wearosdemo;

import android.os.Bundle;
import android.support.wearable.activity.WearableActivity;
import android.view.View;
import android.widget.ImageView;
import android.widget.RelativeLayout;

import androidx.wear.widget.CircularProgressLayout;

public class MainActivity extends WearableActivity implements View.OnClickListener, CircularProgressLayout.OnTimerFinishedListener {


    private ImageView mImageView;
    private CircularProgressLayout circularProgress;
    private RelativeLayout mRecyclerLauncherView;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        initView();
        circularProgress.setTotalTime(5000);
        circularProgress.startTimer();

        // Enables Always-on
        circularProgress.setOnTimerFinishedListener(this);
        circularProgress.setOnClickListener(this);
    }

    @Override
    public void onTimerFinished(CircularProgressLayout layout) {
        // User didn't cancel, perform the action
    }

    @Override
    public void onClick(View view) {
        if (view.equals(circularProgress)) {
            // User canceled, abort the action
            circularProgress.stopTimer();
        }
    }

    private void initView() {
        mImageView = (ImageView) findViewById(R.id.image_view);
        circularProgress = (CircularProgressLayout) findViewById(R.id.circular_progress);
        mRecyclerLauncherView = (RelativeLayout) findViewById(R.id.recycler_launcher_view);
    }
}

你可能感兴趣的:(android wearOs开发)