【发布时间】:2015-03-11 23:40:54
【问题描述】:
在我的 Android Wear 应用程序中,我使用 GridViewPager 并排显示两个布局,您可以在它们之间水平滑动。一页有一个 ScrollView 和子元素。另一个页面有一个用于 WearableListView 的 BoxInsetLayout 和 FrameLayout。如果我在没有 GridViewPager 的情况下单独显示每个页面,我可以很好地滚动 ScrollView 中的文本,并且可以很好地滚动 WearableListView 中的项目列表。但是,当我在 GridViewPager 中将两个页面放在一起时,我不能向上或向下滚动其中的元素,至少在我的 Moto360 上不能。 ScrollView 会在圆形 Android 模拟器中垂直滚动,但 WearableListView 不会。
要么我做错了什么,要么它不应该那样工作。
我的主要 java 类有:
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
this.context = this;
setContentView(R.layout.activity_wear);
GridViewPager pager = (GridViewPager) findViewById(R.id.activity_wear_pager);
pager.setAdapter(new gridViewPagerAdapter());
DotsPageIndicator dotsPageIndicator = (DotsPageIndicator) findViewById(R.id.activity_wear_page_indicator);
dotsPageIndicator.setPager(pager);
}
private class gridViewPagerAdapter extends GridPagerAdapter {
@Override
public int getColumnCount(int arg0) { return 2; }
@Override
public int getRowCount() { return 1; }
@Override
protected Object instantiateItem(ViewGroup container, int row, int col) {
View view = null;
if (col == 0) {
view = LayoutInflater.from(getApplicationContext()).inflate(R.layout.read_page_round, container, false);
mTextView = (TextView) view.findViewById(R.id.text);
}
else {
view = LayoutInflater.from(getApplicationContext()).inflate(R.layout.find_page_round, container, false);
listView = (WearableListView) view.findViewById(R.id.wearable_list);
listView.setAdapter(new Adapter(getApplicationContext(), elements));
listView.setClickListener(WearApplication.this);
}
container.addView(view);
return view;
}
@Override
protected void destroyItem(ViewGroup container, int row, int col, Object view) {
container.removeView((View)view);
}
@Override
public boolean isViewFromObject(View view, Object object) {
return view==object;
}
}
activity_wear.xml:
<?xml version="1.0" encoding="utf-8"?>
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent">
<android.support.wearable.view.GridViewPager
android:id="@+id/activity_wear_pager"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:keepScreenOn="true"/>
<android.support.wearable.view.DotsPageIndicator
android:id="@+id/activity_wear_page_indicator"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal|bottom">
</android.support.wearable.view.DotsPageIndicator>
</FrameLayout>
read_page_round.xml:
<?xml version="1.0" encoding="utf-8"?>
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/scroll"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".WearApplication"
tools:deviceIds="wear_round">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<TextView
android:id="@+id/text"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:paddingTop="5dp"
android:paddingRight="15dp"
android:paddingBottom="60dp"
android:paddingLeft="15dp"
android:layout_centerHorizontal="true"
android:layout_centerVertical="true"
style="@style/wear_main_text"/>
(Other TextView items)
</LinearLayout>
</ScrollView>
find_page_round.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:background="@color/white"
android:layout_height="match_parent"
android:layout_width="match_parent">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<TextView
android:layout_width="match_parent"
android:layout_height="60dp"
android:gravity="center_vertical|center_horizontal"
android:text="Select List"
style="@style/wear_main_app"/>
<FrameLayout
android:id="@+id/frame_layout"
android:layout_height="match_parent"
android:layout_width="match_parent"
app:layout_box="left|bottom|right">
<android.support.wearable.view.WearableListView
android:id="@+id/wearable_list"
android:layout_height="match_parent"
android:layout_width="match_parent">
</android.support.wearable.view.WearableListView>
</FrameLayout>
</LinearLayout>
</android.support.wearable.view.BoxInsetLayout>
【问题讨论】: