其他分享
首页 > 其他分享> > Android Wear:CardScrollView无法滚动?

Android Wear:CardScrollView无法滚动?

作者:互联网

我在我的项目中使用CardScrollView和CardFrame,但CardScrollView无法滚动,这是我的代码,有什么建议吗?

CardScrollViewActivity.java

public class CardScrollViewActivity extends Activity {

    private CardFrame cardFrame;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.card_scroll_view);
        cardFrame=(CardFrame)findViewById(R.id.card_frame);
        cardFrame.setExpansionDirection(CardFrame.EXPAND_UP);
        cardFrame.setExpansionEnabled(true);
        cardFrame.setExpansionFactor(CardFrame.NO_EXPANSION);
    }
}

card_scroll_view.xml

<android.support.wearable.view.CardScrollView
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:orientation="vertical"
    android:layout_width="match_parent"
    android:layout_height="wrap_content">

    <android.support.wearable.view.CardFrame
        android:id="@+id/card_frame"
        android:layout_width="match_parent"
        android:layout_height="wrap_content">
            <TextView
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:padding="5dp"
                android:text="TestTextView\nTestTextView\nTestTextView\nTestTextView\nTestTextView\nTestTextView\nTestTextView\nTestTextView"/>
    </android.support.wearable.view.CardFrame>
</android.support.wearable.view.CardScrollView>

解决方法:

CardScrollView似乎不像ScrollView那样工作.

您可以使用ScrollView包装CardFrame.

<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent">

    <FrameLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:orientation="vertical">

        <android.support.wearable.view.CardFrame
            android:id="@+id/cardFrame"
            android:layout_width="match_parent"
            android:layout_height="wrap_content">

            <TextView
                android:id="@+id/textView"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content" />

        </android.support.wearable.view.CardFrame>

    </FrameLayout>

</ScrollView>

标签:android,wear-os
来源: https://codeday.me/bug/20190830/1769223.html