Android服装:如何在卡片扩展时添加视图

时间:2016-04-08 19:19:07

标签: android android-layout wear-os

我正在Android Wear上创建一张卡片。我希望卡片在折叠时显示两个文本视图,并在展开后显示另外两个按钮。我怎样才能做到这一点? 一些现有的代码:

(活动)

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        CardScrollView cardScrollView =(CardScrollView) findViewById(R.id.card_scroll_view);
        cardScrollView.setCardGravity(Gravity.BOTTOM);
        cardScrollView.setExpansionEnabled(true);
    }

(布局)

<?xml version="1.0" encoding="utf-8"?>
<android.support.wearable.view.CardScrollView
    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"
    app:rectLayout="@layout/rect_activity_main"
    app:roundLayout="@layout/round_activity_main"
    android:background="@color/transparent"
    tools:context="com.example.user.testandroid.MainActivity"
    tools:deviceIds="wear"
    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:id="@+id/card_frame"
        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/title"
                android:textColor="@color/green"
                android:textSize="20sp"/>
            <TextView
                android:fontFamily="sans-serif-light"
                android:layout_height="wrap_content"
                android:layout_width="match_parent"
                android:text="@string/desc"
                android:textColor="@color/red"
                android:textSize="14sp"/>
        </LinearLayout>
    </android.support.wearable.view.CardFrame>
</android.support.wearable.view.CardScrollView>

(我希望在卡展开时添加的布局,但在卡片崩溃时不显示它们)

<LinearLayout
    android:id="@+id/button_layout"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="horizontal">

    <Button
        android:id="@+id/accept"
        android:layout_width="0dp"
        android:layout_weight="0.5"
        android:layout_height="match_parent" />

    <Button
        android:id="@+id/decline"
        android:layout_width="0dp"
        android:layout_weight="0.5"
        android:layout_height="match_parent" />
</LinearLayout>

谢谢!

0 个答案:

没有答案