最近老板要做android手表,我也是第一次接触android手表,一脸茫然,不知道从何下手,android wear API 看的让我更是茫然,原谅我的英语水平不好,在网上找了很多资料,看的更是困惑,只能慢慢尝试。


Context Stream


API 的开始就介绍了Context Stream,我认为它是android wear设计的基础。


Context Stream是一个卡片的垂直列表,每一个显示一个有用的或及时的信息。很像谷歌现在在安卓手机和平板电脑上的功能,用户可以在垂直方向上滑动,从卡到卡。只有一张卡显示在一个时间,和背景照片是用来提供额外的视觉信息。您的应用程序可以创建卡,并将它们注入到流时,他们最有可能是有用的。
这个用户界面模型可以确保用户不必启动许多不同的应用程序来检查更新,他们可以简单地浏览他们的流上的一个简短的更新什么对他们很重要。


既然谷歌推荐使用卡片,我就试着创建我的第一个卡片。
1.android studio 创建一个wear工程。
2。添加布局。我使用的是方形表盘

<?xml version="1.0" encoding="utf-8"?><LinearLayout 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"    android:orientation="vertical"    tools:context="so.wih.android.jjewear.MainActivity"    tools:deviceIds="wear_square">    <TextView        android:id="@+id/text"        android:layout_width="wrap_content"        android:layout_height="wrap_content"        android:text="@string/hello_square" />        <FrameLayout        android:id="@+id/frame_layout"        android:layout_width="match_parent"        android:layout_height="match_parent">FrameLayout>LinearLayout>

3.在代码中添加卡片。

import android.app.Activity;import android.app.FragmentManager;import android.app.FragmentTransaction;import android.os.Bundle;import android.support.wearable.view.CardFragment;import android.support.wearable.view.WatchViewStub;import android.widget.TextView;public class MainActivity extends Activity {    private TextView mTextView;    @Override    protected void onCreate(Bundle savedInstanceState) {        super.onCreate(savedInstanceState);        setContentView(R.layout.activity_main);        final WatchViewStub stub = (WatchViewStub) findViewById(R.id.watch_view_stub);        stub.setOnLayoutInflatedListener(new WatchViewStub.OnLayoutInflatedListener() {            @Override            public void onLayoutInflated(WatchViewStub stub) {                mTextView = (TextView) stub.findViewById(R.id.text);                //添加卡片                FragmentManager mFragmentManager = getFragmentManager();                FragmentTransaction mFragmentTransaction = mFragmentManager.beginTransaction();                CardFragment mCardFragment = CardFragment.create(getString(R.string.cftitle), getString(R.string.cfdesc), R.mipmap.ic_launcher);                mFragmentTransaction.add(R.id.frame_layout,mCardFragment);                mFragmentTransaction.commit();            }        });    }}

4.运行wear项目,就会出现卡片。还可以给布局加个背景,会有更漂亮的效果。

更多相关文章

  1. 推荐10个Android开源项目
  2. 【起航计划 022】2015 起航计划 Android(安卓)APIDemo的魔鬼步伐
  3. android在使用RecyclerView布局里的androidstudio的模拟器虚拟键
  4. 在Ubuntu中和Android中添加开机自启动的守护进程
  5. Android(安卓)Kotlin开发之Hello World
  6. Android(安卓)JNI中记录log
  7. android 中遥控器键值的添加和修改
  8. Android(六)通知、样式、主题、HTML
  9. 生命週期

随机推荐

  1. 腾讯计划斥资超百亿收购搜狗,图什么?
  2. 艾伦人工智能研究所发布 AllenNLP 1.0 ,设
  3. “一挖就走”,中芯国际为什么留不住人?
  4. 图神经网络GNN的可解释性问题与解释方法
  5. html制作一张课程表和用户注册表单
  6. 索赔100亿,诉讼费5000万,小i机器人诉苹果侵
  7. nvidia英伟达GPU:nvidia driver is not l
  8. C语言中的函数概念
  9. 练习2-13 求N分之一序列前N项和 (15分)
  10. 视频时序转换: Amiga PC接口升级为HDMI接