[英]Android Wear: Card Scroll View Does Not Scroll
今天,我正在測試卡片滾動視圖,但是我遵循的所有示例都無法滾動,因此我不確定為什么。
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成為根視圖來檢查根盒插入布局是否可能是問題所在,但問題仍然存在。
如果您這樣做似乎可行:
刪除BoxInsetLayout(CardScrollView成為父視圖)
在CardScrollView上設置setExpansionFactor並在CardFrame上設置屬性。
更新您的代碼:
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);
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.