Android Wear:卡片滚动视图不滚动

时间:2015-05-17 13:27:03

标签: android wear-os

我今天正在测试卡片滚动视图,但是我所遵循的所有示例都没有滚动,我不确定原因。

card_scroll_view_test.xml

<?xml version="1.0" encoding="utf-8"?>
<android.support.wearable.view.BoxInsetLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:background="@color/black">

    <android.support.wearable.view.CardScrollView
        android:id="@+id/card_scroll_view"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        app:layout_box="all">

        <android.support.wearable.view.CardFrame
            android:layout_width="wrap_content"
            android:layout_height="wrap_content">

            <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"
                    android:textColor="@color/black"
                    android:textSize="20sp" />

                <TextView
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:text="@string/big_text"
                    android:textColor="@color/black"
                    android:textSize="14sp" />
            </LinearLayout>
        </android.support.wearable.view.CardFrame>
    </android.support.wearable.view.CardScrollView>
</android.support.wearable.view.BoxInsetLayout>

因此,它包含一个带有线性布局的卡片框架,可以容纳两个子文本视图。最后一个文本视图包含一个非常大的字符串来测试滚动

WearActivity.java

public class WearActivity extends Activity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
         super.onCreate(savedInstanceState);
         setContentView(R.layout.card_scroll_view_test);
         setupCardScrollView();
    }

     private void setupCardScrollView(){
       CardScrollView cardScrollView =
       (CardScrollView) findViewById(R.id.card_scroll_view);
       cardScrollView.setExpansionEnabled(true);
       cardScrollView.setExpansionDirection(CardFrame.EXPAND_DOWN);
       cardScrollView.setCardGravity(Gravity.BOTTOM);
    }
}

我还通过将CardScrollView作为根视图来检查根框插入布局是否可能是问题,但问题仍然存在。

1 个答案:

答案 0 :(得分:0)

如果您:

似乎有效
  1. 删除BoxInsetLayout(CardScrollView成为父视图)

  2. 在CardScrollView上设置setExpansionFactor,并在CardFrame上设置属性。

  3. 更新您的代码:

    private void setupCardScrollView(){
        CardScrollView cardScrollView = 
             (CardScrollView) view.findViewById(R.id.card_scroll_view);
        cardScrollView.setExpansionEnabled(true);
        cardScrollView.setExpansionDirection(1);
        cardScrollView.setExpansionFactor(10.0F);
    
        CardFrame cardFrame = (CardFrame) view.findViewById(R.id.card_frame);
        cardFrame.setExpansionEnabled(true);
        cardFrame.setExpansionDirection(1);
        cardFrame.setExpansionFactor(10.0F);
    
    }