#CardScrollView
Explore tagged Tumblr posts
jacob-cs · 8 years ago
Text
Android wear 개발방법(Creating Cards)
original source : http://www.androiddocs.com/training/wearables/ui/cards.html
Creating Cards
The Wearable UI Library provides implementations of cards specifically designed for wearable devices. This library contains the CardFrame class, which wraps views inside a card-styled frame. CardFrame can only contain one direct child, 어떤 fragment가 cardFrame안에 들어갈지는 layout manager를 통해 결정한다.  
You can add cards to your app in two ways:
Use or extend the CardFragment class.
Add a card inside a CardScrollView in your layout.
Note: This lesson shows you how to add cards to Android Wear activities. Android notifications on wearable devices are also displayed as cards. For more information, see Adding Wearable Features to Notifications. 
Create a Card Fragment
To add a CardFragment to your app:
In your layout, assign an ID to the element that contains the card
Create a CardFragment instance in your activity
Use the fragment manager to add the CardFragment instance to its container
<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">    </FrameLayout> </android.support.wearable.view.BoxInsetLayout>
The following code adds the CardFragment instance to the activity in Figure 1:
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(); }
To create a card with a custom layout using CardFragment, extend this class and override its onCreateContentView method.
Add a CardFrame to Your Layout
You can also add a card directly to your layout definition,
<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"/>            </LinearLayout>        </android.support.wearable.view.CardFrame>    </android.support.wearable.view.CardScrollView> </android.support.wearable.view.BoxInsetLayout>
@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); }
0 notes