学习android wear的开发记录
卡片UI
有两种方式创建卡片布局.
使用CardFragment
布局内容:1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
<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:layout_width="match_parent"
android:layout_height="match_parent" android:id="@+id/container" tools:context=".MainActivity"
tools:deviceIds="wear">
<FrameLayout
android:id="@+id/frame_layout"
android:layout_width="match_parent"
android:layout_height="match_parent"
app:layout_box="bottom">
</FrameLayout>
</android.support.wearable.view.BoxInsetLayout>
MainActivity.java1
2
3
4
5
6
7
8
9
10
11
12
13@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
FragmentManager fragmentManager = getFragmentManager();
FragmentTransaction fragmentTransaction = fragmentManager.beginTransaction();
CardFragment cardFragment = CardFragment.create("标题 ",
"内容",
R.mipmap.ic_launcher);
cardFragment.setCardGravity(Gravity.TOP);
fragmentTransaction.add(R.id.frame_layout, cardFragment);
fragmentTransaction.commit();
}