Android Wear 开发中遇到的 CardFrame can host only one direct child
2016-03-01 00:02
381 查看
Caused by: java.lang.IllegalStateException: CardFrame can host only one direct child
02-29 23:57:35.233 20551-20551/tech.androidstudio.cardframedemoseconde E/AndroidRuntime: at android.support.wearable.view.CardFrame.addView(CardFrame.java:527)
02-29 23:57:35.233 20551-20551/tech.androidstudio.cardframedemoseconde E/AndroidRuntime: at android.view.LayoutInflater.rInflate(LayoutInflater.java:810)
02-29 23:57:35.233 20551-20551/tech.androidstudio.cardframedemoseconde E/AndroidRuntime: at android.view.LayoutInflater.rInflate(LayoutInflater.java:809)
02-29 23:57:35.233 20551-20551/tech.androidstudio.cardframedemoseconde E/AndroidRuntime: at android.view.LayoutInflater.rInflate(LayoutInflater.java:809)
02-29 23:57:35.233 20551-20551/tech.androidstudio.cardframedemoseconde E/AndroidRuntime: at android.view.LayoutInflater.inflate(LayoutInflater.java:504)
02-29 23:57:35.233 20551-20551/tech.androidstudio.cardframedemoseconde E/AndroidRuntime: at android.view.LayoutInflater.inflate(LayoutInflater.java:414)
02-29 23:57:35.233 20551-20551/tech.androidstudio.cardframedemoseconde E/AndroidRuntime: at android.view.LayoutInflater.inflate(LayoutInflater.java:365)
02-29 23:57:35.233 20551-20551/tech.androidstudio.cardframedemoseconde E/AndroidRuntime: at com.android.internal.policy.impl.PhoneWindow.setContentView(PhoneWindow.java:378)
02-29 23:57:35.233 20551-20551/tech.androidstudio.cardframedemoseconde E/AndroidRuntime: at android.app.Activity.setContentView(Activity.java:2145)
02-29 23:57:35.233 20551-20551/tech.androidstudio.cardframedemoseconde E/AndroidRuntime: at tech.androidstudio.cardframedemoseconde.MainActivity.onCreate(MainActivity.java:15)
02-29 23:57:35.233 20551-20551/tech.androidstudio.cardframedemoseconde E/AndroidRuntime: at android.app.Activity.performCreate(Activity.java:5990)
02-29 23:57:35.233 20551-20551/tech.androidstudio.cardframedemoseconde E/AndroidRuntime: at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1106)
02-29 23:57:35.233 20551-20551/tech.androidstudio.cardframedemoseconde E/AndroidRuntime: at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2278)
02-29 23:57:35.233 20551-20551/tech.androidstudio.cardframedemoseconde E/AndroidRuntime: at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2387)
02-29 23:57:35.233 20551-20551/tech.androidstudio.cardframedemoseconde E/AndroidRuntime: at android.app.ActivityThread.access$800(ActivityThread.java:151)
02-29 23:57:35.233 20551-20551/tech.androidstudio.cardframedemoseconde E/AndroidRuntime: at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1303)
02-29 23:57:35.233 20551-20551/tech.androidstudio.cardframedemoseconde E/AndroidRuntime: at android.os.Handler.dispatchMessage(Handler.java:102)
02-29 23:57:35.233 20551-20551/tech.androidstudio.cardframedemoseconde E/AndroidRuntime: at android.os.Looper.loop(Looper.java:135)
02-29 23:57:35.233 20551-20551/tech.androidstudio.cardframedemoseconde E/AndroidRuntime: at android.app.ActivityThread.main(ActivityThread.java:5254)
02-29 23:57:35.233 20551-20551/tech.androidstudio.cardframedemoseconde E/AndroidRuntime: at java.lang.reflect.Method.invoke(Native Method)
02-29 23:57:35.233 20551-20551/tech.androidstudio.cardframedemoseconde E/AndroidRuntime: at java.lang.reflect.Method.invoke(Method.java:372)
02-29 23:57:35.233 20551-20551/tech.androidstudio.cardframedemoseconde E/AndroidRuntime: at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:903)
02-29 23:57:35.233 20551-20551/tech.androidstudio.cardframedemoseconde E/AndroidRuntime: at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:698)
原因 :
CardFrame 只能有一个子组件 ,而我的 代码里面是两个TextView 所以错了
解决的办法:
添加一个 LinearLayout来包裹 刚才的 两个TextView。
02-29 23:57:35.233 20551-20551/tech.androidstudio.cardframedemoseconde E/AndroidRuntime: at android.support.wearable.view.CardFrame.addView(CardFrame.java:527)
02-29 23:57:35.233 20551-20551/tech.androidstudio.cardframedemoseconde E/AndroidRuntime: at android.view.LayoutInflater.rInflate(LayoutInflater.java:810)
02-29 23:57:35.233 20551-20551/tech.androidstudio.cardframedemoseconde E/AndroidRuntime: at android.view.LayoutInflater.rInflate(LayoutInflater.java:809)
02-29 23:57:35.233 20551-20551/tech.androidstudio.cardframedemoseconde E/AndroidRuntime: at android.view.LayoutInflater.rInflate(LayoutInflater.java:809)
02-29 23:57:35.233 20551-20551/tech.androidstudio.cardframedemoseconde E/AndroidRuntime: at android.view.LayoutInflater.inflate(LayoutInflater.java:504)
02-29 23:57:35.233 20551-20551/tech.androidstudio.cardframedemoseconde E/AndroidRuntime: at android.view.LayoutInflater.inflate(LayoutInflater.java:414)
02-29 23:57:35.233 20551-20551/tech.androidstudio.cardframedemoseconde E/AndroidRuntime: at android.view.LayoutInflater.inflate(LayoutInflater.java:365)
02-29 23:57:35.233 20551-20551/tech.androidstudio.cardframedemoseconde E/AndroidRuntime: at com.android.internal.policy.impl.PhoneWindow.setContentView(PhoneWindow.java:378)
02-29 23:57:35.233 20551-20551/tech.androidstudio.cardframedemoseconde E/AndroidRuntime: at android.app.Activity.setContentView(Activity.java:2145)
02-29 23:57:35.233 20551-20551/tech.androidstudio.cardframedemoseconde E/AndroidRuntime: at tech.androidstudio.cardframedemoseconde.MainActivity.onCreate(MainActivity.java:15)
02-29 23:57:35.233 20551-20551/tech.androidstudio.cardframedemoseconde E/AndroidRuntime: at android.app.Activity.performCreate(Activity.java:5990)
02-29 23:57:35.233 20551-20551/tech.androidstudio.cardframedemoseconde E/AndroidRuntime: at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1106)
02-29 23:57:35.233 20551-20551/tech.androidstudio.cardframedemoseconde E/AndroidRuntime: at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2278)
02-29 23:57:35.233 20551-20551/tech.androidstudio.cardframedemoseconde E/AndroidRuntime: at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2387)
02-29 23:57:35.233 20551-20551/tech.androidstudio.cardframedemoseconde E/AndroidRuntime: at android.app.ActivityThread.access$800(ActivityThread.java:151)
02-29 23:57:35.233 20551-20551/tech.androidstudio.cardframedemoseconde E/AndroidRuntime: at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1303)
02-29 23:57:35.233 20551-20551/tech.androidstudio.cardframedemoseconde E/AndroidRuntime: at android.os.Handler.dispatchMessage(Handler.java:102)
02-29 23:57:35.233 20551-20551/tech.androidstudio.cardframedemoseconde E/AndroidRuntime: at android.os.Looper.loop(Looper.java:135)
02-29 23:57:35.233 20551-20551/tech.androidstudio.cardframedemoseconde E/AndroidRuntime: at android.app.ActivityThread.main(ActivityThread.java:5254)
02-29 23:57:35.233 20551-20551/tech.androidstudio.cardframedemoseconde E/AndroidRuntime: at java.lang.reflect.Method.invoke(Native Method)
02-29 23:57:35.233 20551-20551/tech.androidstudio.cardframedemoseconde E/AndroidRuntime: at java.lang.reflect.Method.invoke(Method.java:372)
02-29 23:57:35.233 20551-20551/tech.androidstudio.cardframedemoseconde E/AndroidRuntime: at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:903)
02-29 23:57:35.233 20551-20551/tech.androidstudio.cardframedemoseconde E/AndroidRuntime: at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:698)
原因 :
CardFrame 只能有一个子组件 ,而我的 代码里面是两个TextView 所以错了
<android.support.wearable.view.BoxInsetLayout 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" > <android.support.wearable.view.CardScrollView android:id="@+id/cardscrollview" android:layout_width="match_parent" android:layout_height="wrap_content" android:gravity="bottom"> <android.support.wearable.view.CardFrame android:layout_width="match_parent" android:layout_height="fill_parent"> <TextView android:layout_width="match_parent" android:layout_height="wrap_content" android:text="Hello World"/> <TextView android:layout_width="match_parent" android:layout_height="wrap_content" android:text="Desctiption"/> </android.support.wearable.view.CardFrame> </android.support.wearable.view.CardScrollView> </android.support.wearable.view.BoxInsetLayout>
解决的办法:
添加一个 LinearLayout来包裹 刚才的 两个TextView。
<android.support.wearable.view.CardFrame android:layout_width="match_parent" android:layout_height="fill_parent"> <LinearLayout android:layout_width="match_parent" android:layout_height="wrap_content" android:orientation="vertical"> <TextView android:layout_width="match_parent" android:layout_height="wrap_content" android:text="Hello World"/> <TextView android:layout_width="match_parent" android:layout_height="wrap_content" android:text="Desctiption"/> </LinearLayout> </android.support.wearable.view.CardFrame>
相关文章推荐
- android studio 快捷笔记
- 怎么实现iMindMap Android中主题关联线的添加
- 高仿人人网客户端Android版项目源码
- Android Fragment中监听事件
- android studio recent projects
- Android data/{package}/ 目录介绍
- Android源码树中C代码的编译
- android常见异常总结
- android ktv 开发过程5-android调用ffmpeg成功
- FFmpeg在Android上的移植优化步骤
- Android中的线程
- android开发之路02(浅谈BroadcastReceiver)
- Android 2016新技术
- Android学习笔记之Broadcast Receiver
- android-studio 开发 和代理服务器
- Android工具类——LoadingUtils
- Android之ListView性能优化
- RN 与 Android 代码交互
- 自定义View基础与原理
- Android多线程断点下载