カスタムの内部を持つレイアウトがあり、ViewPagerが垂直方向にスクロールしません。カスタムScrollViewは、ScrollViewでスワイプする恐ろしいタブを修正するために使用されます。ViewPager
ScrollView
はい、スクロールするのに十分なコンテンツがあり、下のボタンがある場合とない場合で試しました。
私は3つのタブがあるActionBarを使用していますが、現在のコードでは左右にうまくスワイプできます。
私の目標は、保存やキャンセルなどのいくつかのアクションアイテムの下部バーを作成し、アクションバーと下部のボタンの間の部分を垂直方向にスクロールするViewPagerにすることです。
私はあまりにも多くの組み合わせを試しましたが、今このラブレターをあなたに送っています。何か案は?どんな助けでもありがたいです、そして必要ならば追加の詳細を遠慮なく尋ねてください。
main.xml
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
<LinearLayout
android:id="@+id/footer"
style="@android:style/Holo.ButtonBar"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:orientation="horizontal" >
<Button
android:id="@+id/saveButton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="Save" />
<Button
android:id="@+id/cancelButton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="Cancel" />
</LinearLayout>
<com.blah.hootiehoo.ViewPagerCompatScrollView
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_above="@id/footer"
android:fillViewport="true" >
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical"
android:scrollbarAlwaysDrawVerticalTrack="true"
android:scrollbars="vertical" >
<android.support.v4.view.ViewPager
android:id="@+id/pager"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_weight="1"
android:scrollbarAlwaysDrawVerticalTrack="true"
android:scrollbars="vertical" >
</android.support.v4.view.ViewPager>
</LinearLayout>
</com.blah.hootiehoo.ViewPagerCompatScrollView>
</RelativeLayout>
MainActivity.java
ViewPager mViewPager;
TabsAdapter mTabsAdapter;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
mViewPager = (ViewPager)findViewById(R.id.pager);
// setup action bar for tabs
ActionBar actionBar = getActionBar();
actionBar.setNavigationMode(ActionBar.NAVIGATION_MODE_TABS);
actionBar.setDisplayShowTitleEnabled(true);
actionBar.setDisplayHomeAsUpEnabled(true);
mTabsAdapter = new TabsAdapter(this, mViewPager);
Tab tab = actionBar.newTab();
// tab setup
mTabsAdapter.addTab(/*** stuff ***/);
// add 2 more tabs, etc
}
ViewPagerCompatScrollView.java ここから取得しました。
public class ViewPagerCompatScrollView extends ScrollView {
private float xDistance, yDistance, lastX, lastY;
public ViewPagerCompatScrollView(Context context, AttributeSet attrs) {
super(context, attrs);
}
@Override
public boolean onInterceptTouchEvent(MotionEvent ev) {
switch (ev.getAction()) {
case MotionEvent.ACTION_DOWN:
xDistance = yDistance = 0f;
lastX = ev.getX();
lastY = ev.getY();
break;
case MotionEvent.ACTION_MOVE:
final float curX = ev.getX();
final float curY = ev.getY();
xDistance += Math.abs(curX - lastX);
yDistance += Math.abs(curY - lastY);
lastX = curX;
lastY = curY;
if(xDistance > yDistance)
return false;
}
return super.onInterceptTouchEvent(ev);
}
}