首页 > 其他分享 >Android Wear 开发 (一),阿里、腾讯、华为、京东等多家大厂最新安卓面试题

Android Wear 开发 (一),阿里、腾讯、华为、京东等多家大厂最新安卓面试题

时间:2024-09-23 21:48:59浏览次数:3  
标签:面试题 layout parent 安卓 height Wear android id match

importandroid.support.v4.app.NotificationCompat.WearableExtender;

普通通知栏
  1. 手机:普通的通知栏在手机上的效果应该都不陌生,这里就不展开说明

  2. 手表:手表端的效果是由2张卡片构成的,第一张是手机通知栏的信息组成,第二张是点击开发手机应用,具体的效果与手机通知栏的点击事件一致,也就是说,如果通知栏没有设置点击事件,那么就不会有第二张卡片。另外,默认的背景色是由应用图标所决定的,是取主要的颜色值

以上是最原始的通知栏效果,没有进行手表端适配处理的。(其实普通的通知栏你都不用做。。。。。。)

添加Wear扩展属性的通知栏

扩展属性

·        多张卡片:通知栏的多张内容展示

·        自定义动作按钮:自定义Action按钮的事件处理

·        设置背景:设置通知栏的背景色

·        堆叠多张卡片:通知栏卡片的堆叠

·        语音回复:

Wear 上的UI开发

Android Wear apps用户界面不同于在手机设备上构建。需要遵循AndroidWear设计规范UI模式,以确保应用通过针对可穿戴设备而优化的一致用户体验。

UI模式主要通过以下方式实现:

  1. 卡片

  2. 倒计时和确认

  3. 长按消失

  4. 2d pickers

  5. 选择列表

Wearable UI Library是Android SDk中Google Repository的一部分,提供帮助你实现这些模式的类,并可以创建同时适配运行在圆形和方形屏幕设备上的布局。

定义布局

当创建android wear布局的时候,要考虑设备有两种屏幕,方形和圆形。任何位于屏幕角落的内容都会被圆形屏幕裁剪掉。

Wearable UI Library提供两种方式解决这个问题:

1、为圆形和方形屏幕的设备定义两套布局。在运行时检测设备屏幕并渲染不同的布局。

2、使用Wearable UILibrary中一种特殊的布局来包住你的布局。这个布局会根据设备屏幕来加载不同的布局文件。

典型的办法是第一种,如果布局简单可以直接使用第二种。

为圆形和方形屏幕定义不同的布局

Wearable UI Library中的WatchViewStub这个类可以让你为圆形和方形屏幕定义不同的布局。这个类会在运行时检测屏幕形状并渲染相应的布局。

1、在你的activity布局文件中添加WatchViewStub元素

2、使用rectLayout属性为方形屏幕指定布局文件

3、使用roundLayout属性为圆形屏幕指定布局文件

[java]

view plain

copy

print

?

  1. <android.support.wearable.view.WatchViewStub

  2. xmlns:android=”http://schemas.android.com/apk/res/android”

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

  4. xmlns:tools=”http://schemas.android.com/tools”

  5. android:id=”@+id/watch_view_stub”

  6. android:layout_width=”match_parent”

  7. android:layout_height=”match_parent”

  8. app:rectLayout=”@layout/rect_activity_wear”

  9. app:roundLayout=”@layout/round_activity_wear”>

  10. </android.support.wearable.view.WatchViewStub>

  11. @Override

  12. protected void onCreate(Bundle savedInstanceState) {

  13. super.onCreate(savedInstanceState);

  14. setContentView(R.layout.activity_wear);

  15. }

  16. 访问布局控件

  17. 渲染布局文件不是同步的,所以要设置一个回调来监听WatchViewStub渲染完成。

  18. @Override

  19. protected void onCreate(Bundle savedInstanceState) {

  20. super.onCreate(savedInstanceState);

  21. setContentView(R.layout.activity_wear);

  22. WatchViewStub stub = (WatchViewStub) findViewById(R.id.watch_view_stub);

  23. stub.setOnLayoutInflatedListener(new WatchViewStub.OnLayoutInflatedListener() {

  24. @Override public void onLayoutInflated(WatchViewStub stub) {

  25. // Now you can access your views

  26. TextView tv = (TextView) stub.findViewById(R.id.text);

  27. }

  28. });

  29. }

<android.support.wearable.view.WatchViewStub

xmlns:android=“http://schemas.android.com/apk/res/android”

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

xmlns:tools=“http://schemas.android.com/tools”

android:id=“@+id/watch_view_stub”

android:layout_width=“match_parent”

android:layout_height=“match_parent”

app:rectLayout=“@layout/rect_activity_wear”

app:roundLayout=“@layout/round_activity_wear”>

</android.support.wearable.view.WatchViewStub>

@Override

protected void onCreate(Bundle savedInstanceState) {

super.onCreate(savedInstanceState);

setContentView(R.layout.activity_wear);

}

访问布局控件

渲染布局文件不是同步的,所以要设置一个回调来监听WatchViewStub渲染完成。

@Override

protected void onCreate(Bundle savedInstanceState) {

super.onCreate(savedInstanceState);

setContentView(R.layout.activity_wear);

WatchViewStub stub = (WatchViewStub) findViewById(R.id.watch_view_stub);

stub.setOnLayoutInflatedListener(new WatchViewStub.OnLayoutInflatedListener() {

@Override public void onLayoutInflated(WatchViewStub stub) {

// Now you can access your views

TextView tv = (TextView) stub.findViewById(R.id.text);

}

});

}

创建卡片

卡片风格可以让不同应用呈现给用户一致的风格和交互。Wearable UI库中实现了为可穿戴设备特殊设计的卡片控件。这个库包含了CardFrame类,CardFrame只能包含一个直接子view,你可以添加其他自定义内容插入到卡片中。

你有两种办法来添加卡片:

1、使用或继承CardFragment2、在你的布局中添加CardScrollView

创建CardFragment

CardFragment 提供一个默认卡片布局,包含标题、图标、描述。

外链图片转存失败,源站可能有防盗链机制,建议将图片保存下来直接上传

创建CardFragment的步骤:

1、在你的布局中,分配一个id给CardFragment

2、在你的activity中新建一个CardFragment实例

3、使用fragmentmanager添加CardFragment实例

[html]

view plain

copy

print

?

  1. <android.support.wearable.view.BoxInsetLayout

  2. xmlns:android=“http://schemas.android.com/apk/res/android”

  3. xmlns:app=“http://schemas.android.com/apk/res-auto”

  4. android:background=“@drawable/robot_background”

  5. android:layout_height=“match_parent”

  6. android:layout_width=“match_parent”>

  7. <FrameLayout

  8. android:id=“@+id/frame_layout”

  9. android:layout_width=“match_parent”

  10. android:layout_height=“match_parent”

  11. app:layout_box=“bottom”>

  12. </FrameLayout>

  13. </android.support.wearable.view.BoxInsetLayout>

<android.support.wearable.view.BoxInsetLayout

xmlns:android=“http://schemas.android.com/apk/res/android”

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

android:background=“@drawable/robot_background”

android:layout_height=“match_parent”

android:layout_width=“match_parent”>

<FrameLayout

android:id=“@+id/frame_layout”

android:layout_width=“match_parent”

android:layout_height=“match_parent”

app:layout_box=“bottom”>

</android.support.wearable.view.BoxInsetLayout>

Activity``代码中:

[java]

view plain

copy

print

?

  1. protected void onCreate(Bundle savedInstanceState) {

  2. super.onCreate(savedInstanceState);

  3. setContentView(R.layout.activity_wear_activity2);

  4. FragmentManager fragmentManager = getFragmentManager();

  5. FragmentTransaction fragmentTransaction = fragmentManager.beginTransaction();

  6. CardFragment cardFragment = CardFragment.create(getString(R.string.cftitle),

  7. getString(R.string.cfdesc),

  8. R.drawable.p);

  9. fragmentTransaction.add(R.id.frame_layout, cardFragment);

  10. fragmentTransaction.commit();

  11. }

protected void onCreate(Bundle savedInstanceState) {

super.onCreate(savedInstanceState);

setContentView(R.layout.activity_wear_activity2);

FragmentManager fragmentManager = getFragmentManager();

FragmentTransaction fragmentTransaction = fragmentManager.beginTransaction();

CardFragment cardFragment = CardFragment.create(getString(R.string.cftitle),

getString(R.string.cfdesc),

R.drawable.p);

fragmentTransaction.add(R.id.frame_layout, cardFragment);

fragmentTransaction.commit();

}

如果要使用CardFragment来创建一个自定义布局的卡片,可以继承这个类然后重写onCreateContentView方法。

添加CardFrame 到你的布局中

你也可以直接添加一个卡片到你的布局中。

[html] view plain copy

print ?

  1. <android.support.wearable.view.BoxInsetLayout

  2. xmlns:android=“http://schemas.android.com/apk/res/android”

  3. xmlns:app=“http://schemas.android.com/apk/res-auto”

  4. android:background=“@drawable/robot_background”

  5. android:layout_height=“match_parent”

  6. android:layout_width=“match_parent”>

  7. <android.support.wearable.view.CardScrollView

  8. android:id=“@+id/card_scroll_view”

  9. android:layout_height=“match_parent”

  10. android:layout_width=“match_parent”

  11. app:layout_box=“bottom”>

  12. <android.support.wearable.view.CardFrame

  13. android:layout_height=“wrap_content”

  14. android:layout_width=“fill_parent”>

  15. <LinearLayout

  16. android:layout_height=“wrap_content”

  17. android:layout_width=“match_parent”

  18. android:orientation=“vertical”

  19. android:paddingLeft=“5dp”>

  20. <TextView

  21. android:fontFamily=“sans-serif-light”

  22. android:layout_height=“wrap_content”

  23. android:layout_width=“match_parent”

  24. android:text=“@string/custom_card”

  25. android:textColor=“@color/black”

  26. android:textSize=“20sp”/>

  27. <TextView

  28. android:fontFamily=“sans-serif-light”

  29. android:layout_height=“wrap_content”

  30. android:layout_width=“match_parent”

  31. android:text=“@string/description”

  32. android:textColor=“@color/black”

  33. android:textSize=“14sp”/>

  34. </LinearLayout>

  35. </android.support.wearable.view.CardFrame>

  36. </android.support.wearable.view.CardScrollView>

  37. </android.support.wearable.view.BoxInsetLayout>

<android.support.wearable.view.BoxInsetLayout

xmlns:android=“http://schemas.android.com/apk/res/android”

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

android:background=“@drawable/robot_background”

android:layout_height=“match_parent”

android:layout_width=“match_parent”>

<android.support.wearable.view.CardScrollView

android:id=“@+id/card_scroll_view”

android:layout_height=“match_parent”

android:layout_width=“match_parent”

app:layout_box=“bottom”>

<android.support.wearable.view.CardFrame

android:layout_height=“wrap_content”

android:layout_width=“fill_parent”>

<LinearLayout

android:layout_height=“wrap_content”

android:layout_width=“match_parent”

android:orientation=“vertical”

android:paddingLeft=“5dp”>

<TextView

android:fontFamily=“sans-serif-light”

android:layout_height=“wrap_content”

android:layout_width=“match_parent”

android:text=“@string/custom_card”

android:textColor=“@color/black”

android:textSize=“20sp”/>

<TextView

android:fontFamily=“sans-serif-light”

android:layout_height=“wrap_content”

android:layout_width=“match_parent”

android:text=“@string/description”

android:textColor=“@color/black”

android:textSize=“14sp”/>

</android.support.wearable.view.CardFrame>

</android.support.wearable.view.CardScrollView>

</android.support.wearable.view.BoxInsetLayout>

CardScrollView 元素可以让你设置卡片的gravity。

[java]

view plain

copy

print

?

  1. @Override

  2. protected void onCreate(Bundle savedInstanceState) {

  3. super.onCreate(savedInstanceState);

  4. setContentView(R.layout.activity_wear_activity2);

  5. CardScrollView cardScrollView =

  6. (CardScrollView) findViewById(R.id.card_scroll_view);

  7. cardScrollView.setCardGravity(Gravity.BOTTOM);

  8. }

@Override

protected void onCreate(Bundle savedInstanceState) {

super.onCreate(savedInstanceState);

setContentView(R.layout.activity_wear_activity2);

CardScrollView cardScrollView =

(CardScrollView) findViewById(R.id.card_scroll_view);

cardScrollView.setCardGravity(Gravity.BOTTOM);

}

CardScrollView 会检测设备的屏幕形状,所以在方形和圆形屏幕上显示卡片的方式不同。可以在外面嵌套一个BoxInsetLayout。

创建列表

列表可以让用户在一系列选项中选择某一项。WearableUI库包含WearableListView类,是专为穿戴设备优化的实现类。

创建列表的步骤:

1、在你activity的布局中添加WearableListView元素

2、创建一个自定义布局来实现你的list item

3、创建一个adapter装载进这个listview

外链图片转存失败,源站可能有防盗链机制,建议将图片保存下来直接上传

添加一个listview

[html] view plain copy

print ?

  1. <android.support.wearable.view.BoxInsetLayout

  2. xmlns:android=“http://schemas.android.com/apk/res/android”

  3. xmlns:app=“http://schemas.android.com/apk/res-auto”

  4. android:background=“@drawable/robot_background”

  5. android:layout_height=“match_parent”

  6. android:layout_width=“match_parent”>

  7. <FrameLayout

  8. android:id=“@+id/frame_layout”

  9. android:layout_height=“match_parent”

  10. android:layout_width=“match_parent”

  11. app:layout_box=“left|bottom|right”>

  12. <android.support.wearable.view.WearableListView

  13. android:id=“@+id/wearable_list”

  14. android:layout_height=“match_parent”

  15. android:layout_width=“match_parent”>

  16. </android.support.wearable.view.WearableListView>

  17. </FrameLayout>

  18. </android.support.wearable.view.BoxInsetLayout>

<android.support.wearable.view.BoxInsetLayout

xmlns:android=“http://schemas.android.com/apk/res/android”

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

android:background=“@drawable/robot_background”

android:layout_height=“match_parent”

android:layout_width=“match_parent”>

<FrameLayout

android:id=“@+id/frame_layout”

android:layout_height=“match_parent”

android:layout_width=“match_parent”

app:layout_box=“left|bottom|right”>

<android.support.wearable.view.WearableListView

android:id=“@+id/wearable_list”

android:layout_height=“match_parent”

android:layout_width=“match_parent”>

</android.support.wearable.view.WearableListView>

</android.support.wearable.view.BoxInsetLayout>

其他的ListView绑定数据显示在这里就不啰嗦了

Wear 数据层的通信

android wear数据层API,是Google Play services的一部分,提供手持设备和android wear应用的通信通道。这个API包含一个数据对象集合和数据层重要事件的监听:

Data Items

一个DataItem提供数据存储和手持设备与android wear设备间的自动同步

Messages

MessageApi类可以发送消息,可用于远程过程调用(RPC),例如通过android wear设备来控制手持设备上的媒体播放器,或者从手持设备上向android wear设备发起一个intent。

消息也可以用于单向请求或者一个请求/响应交流模型。如果手持设备和android wear设备已连接,系统会按顺序发送消息并返回一个成功的结果状态。如果设备间未连接,则返回错误。一个成功的结果状态不能表明消息发送成功,也可能是接受到结果状态后设备间断开了连接。

Asset

Asset对象是为了发送二进制原始数据,例如一张图片。你需要附加assets给data items,并且系统自动会帮你传输,通过缓存大的assets保护蓝牙带宽来避免重新传输。

WearableListenerService(针对service)

结尾

最后,针对上面谈的内容,给大家推荐一个Android资料,应该对大家有用。

首先是一个知识清单:(对于现在的Android及移动互联网来说,我们需要掌握的技术)

泛型原理丶反射原理丶Java虚拟机原理丶线程池原理丶
注解原理丶注解原理丶序列化
Activity知识体系(Activity的生命周期丶Activity的任务栈丶Activity的启动模式丶View源码丶Fragment内核相关丶service原理等)
代码框架结构优化(数据结构丶排序算法丶设计模式)
APP性能优化(用户体验优化丶适配丶代码调优)
热修复丶热升级丶Hook技术丶IOC架构设计
NDK(c编程丶C++丶JNI丶LINUX)
如何提高开发效率?
MVC丶MVP丶MVVM
微信小程序
Hybrid
Flutter

接下来是资料清单:(敲黑板!!!

领取通道在这里给你们摆上了~

点击我的GitHub免费获取

1.数据结构和算法

2.设计模式

3.全套体系化高级架构视频;七大主流技术模块,视频+源码+笔记

4.面试专题资料包(怎么能少了一份全面的面试题总结呢~)

不论遇到什么困难,都不应该成为我们放弃的理由!共勉~

如果你看到了这里,觉得文章写得不错就给个赞呗?如果你觉得那里值得改进的,请给我留言。一定会认真查询,修正不足。谢谢。


,针对上面谈的内容,给大家推荐一个Android资料,应该对大家有用。**

首先是一个知识清单:(对于现在的Android及移动互联网来说,我们需要掌握的技术)

泛型原理丶反射原理丶Java虚拟机原理丶线程池原理丶
注解原理丶注解原理丶序列化
Activity知识体系(Activity的生命周期丶Activity的任务栈丶Activity的启动模式丶View源码丶Fragment内核相关丶service原理等)
代码框架结构优化(数据结构丶排序算法丶设计模式)
APP性能优化(用户体验优化丶适配丶代码调优)
热修复丶热升级丶Hook技术丶IOC架构设计
NDK(c编程丶C++丶JNI丶LINUX)
如何提高开发效率?
MVC丶MVP丶MVVM
微信小程序
Hybrid
Flutter

[外链图片转存中…(img-W5mzNekU-1727083637867)]

接下来是资料清单:(敲黑板!!!

领取通道在这里给你们摆上了~

点击我的GitHub免费获取

1.数据结构和算法

[外链图片转存中…(img-03tqzTht-1727083637867)]

2.设计模式

[外链图片转存中…(img-xadyq7Zv-1727083637867)]

3.全套体系化高级架构视频;七大主流技术模块,视频+源码+笔记

[外链图片转存中…(img-XZ0IFwDl-1727083637868)]

4.面试专题资料包(怎么能少了一份全面的面试题总结呢~)

[外链图片转存中…(img-XFkVC1T2-1727083637868)]

不论遇到什么困难,都不应该成为我们放弃的理由!共勉~

如果你看到了这里,觉得文章写得不错就给个赞呗?如果你觉得那里值得改进的,请给我留言。一定会认真查询,修正不足。谢谢。

[外链图片转存中…(img-6y4kK7If-1727083637868)]

标签:面试题,layout,parent,安卓,height,Wear,android,id,match
From: https://blog.csdn.net/2401_87545672/article/details/142463799

相关文章

  • Vue 2&3进阶面试题:(第五天)
    目录17.keep-alive18.$router和$route的区别19.vue-router路由模式有几种?20.vue的路由传参param和query的区别17.keep-alivekeep-alive是Vue的内置组件,当它包裹动态组件时,会缓存不活动的组件实例,而不是销毁它们。keep-alive是一个抽象组件:它自身不会渲染成一个DO......
  • MySQL 增删操作面试题
    在数据库操作中,数据的增删是最基础也是最常见的操作。MySQL作为流行的关系型数据库,增删操作在面试中经常涉及。本文准备了30道关于MySQL增删操作的面试题,按照简单、中等、困难的难度划分,并提供了详细的答案和对应的SQL语句。通过这些问题,可以深入理解MySQL在实际应用中的增删操作。......
  • 2024最新版Java面试题及答案汇总
    1.对字符串的都有哪些方法?详细说明下。具体有String、StringBuffer和StringBuilder这三个类。String是不可变类,每次操作都会生成新的String对象,并将结果指针指向新的对象,由此会产生内存碎片。如果要频繁对字符串修改,建议采用StringBuffer和StringBuilder。StringBuff......
  • 2024Java核心面试题合集
    1.保证并发安全的三大特性? 原子性:一次或多次操作在执行期间不被其他线程影响可见性:当一个线程在工作内存修改了变量,其他线程能立刻知道有序性:JVM对指令的优化会让指令执行顺序改变,有序性是禁止指令重排2.volatile保证变量的可见性和有序性,不保证原子性。使用了volatile......
  • 2024年全新Java面试题整理
    1、多线程的价值?(1)发挥多核CPU的优势多线程,可以真正发挥出多核CPU的优势来,达到充分利用CPU的目的,采用多线程的方式去同时完成几件事情而不互相干扰。(2)防止阻塞从程序运行效率的角度来看,单核CPU不但不会发挥出多线程的优势,反而会因为在单核CPU上运行多线程导致线......
  • 【unity开发】以OPPO手机为例,如何连接安卓设备并调试unity程序
    1.有线调试下面全程以oppo手机为例:1.打开手机开发者模式设置->关于手机->版本信息->狂点版本号直到弹出提示打开开发者模式即可2.打开USB调试打开开发者模式之后在设置->其他设置->开发者选项->USB调试打开即可3.USB数据线连接使用USB数据线连接你的手机和电脑,并确保USB......
  • 安卓13删除下拉栏中的设置按钮 android13删除设置按钮
    总纲android13rom开发总纲说明文章目录1.前言2.问题分析3.代码分析4.代码修改5.编译6.彩蛋1.前言  顶部导航栏下拉可以看到,底部这里有个设置按钮,点击可以进入设备的设置页面,这里我们将更改为删除,不同用户通过这个地方进入设置。也就是下面这个按钮。......
  • python面试题
    python是什么?Python是一种开放原始码、直译式、可携式、面向对象的程序语言,具有模块、多线程、异常处理以及自动内存管理功能。广泛应用包括Web开发(如Django和Flask框架)、数据科学(如Pandas和NumPy库)、机器学习(如TensorFlow和PyTorch框架)、自动化脚本、科学计算等。算法是什么?......
  • Java面试题大全(全网最全,持续更新)初级(2)
    1.基础语法1.1.Java的数据类型有哪些?Java有两种数据类型:基本数据类型(PrimitiveTypes):包括byte、short、int、long、float、double、char、boolean。引用数据类型(ReferenceTypes):包括类、接口、数组等。1.2.final关键字有什么作用?final关键字可以用来修饰类、方......
  • Java集合类面试题:Map接口(链表、HashMap、红黑树)
    收集大量Java经典面试题目......