我不确定如何将这两个寻呼机集成到一个视图中。我想做的是,图像应该能够垂直和水平滑动。该屏幕将在屏幕中具有页面指示器。
scrollView = (ScrollView) findViewById(R.id.scroll_view);
contentView = (ViewGroup) findViewById(R.id.content);
scrollView.setOnTouchListener(new ScrollPager(scrollView, contentView));
scrollView.post(new Runnable()
{
public void run()
{
scrollView.scrollTo(0, contentView.getPaddingTop());
}
});
final PagerControl control = (PagerControl) findViewById(R.id.control);
final HorizontalPager pager = (HorizontalPager) findViewById(R.id.pager);
control.setNumPages(pager.getChildCount());
pager.addOnScrollListener(new HorizontalPager.OnScrollListener() {
public void onScroll(int scrollX) {
//Log.d("TestActivity", "scrollX=" + scrollX);
float scale = (float) (pager.getPageWidth() * pager.getChildCount()) / (float) control.getWidth();
control.setPosition((int) (scrollX / scale));
}
public void onViewScrollFinished(int currentPage) {
//Log.d("TestActivity", "viewIndex=" + currentPage);
control.setCurrentPage(currentPage);
}
});
和 xml 是
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:example="http://schemas.android.com/apk/res/com.example.page"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
>
<com.example.page.HorizontalPager
android:id="@+id/pager"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
example:pageWidth="250dip"
>
<ScrollView
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/scroll_view"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<LinearLayout
android:id="@+id/content"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical"
android:paddingTop="200dip"
android:paddingBottom="200dip">
<TextView
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:gravity="center"
android:background="#0a0"
android:text="Text 1"
android:focusable="true"
/>
<TextView
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:gravity="center"
android:background="#00a"
android:text="Text 2"
android:focusable="true"
/>
<Button
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:text="Text 3"
/>
<TextView
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:gravity="center"
android:background="#a00"
android:text="Text 4"
android:focusable="true"
/>
<TextView
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:gravity="center"
android:background="#0aa"
android:text="Text 5"
android:focusable="true"
/>
</ScrollView>
</com.example.page.HorizontalPager>
<com.example.page.PagerControl
android:id="@+id/control"
android:layout_width="fill_parent"
android:layout_height="4dip"
android:layout_margin="8dip"
example:roundRectRadius="2dip"
/>
</LinearLayout>