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