0
私のコードでは、HorizontalScrollViewを使用してスワイプを実装しています。適切な作業コードがあります。スワイプの左または右にスワイプしています。そのために私はその中でいくつかの余分なコードを追加しましたが、そのコードは動作していないことを下回っているHorizontaScrollViewの問題と画面のスワイプ
public class PaginationLayout extends LinearLayout {
private int mPageActive = 0;
private HorizontalScrollView mScroll;
private LinearLayout mBar;
public PaginationLayout(Context context) {
super(context);
setOrientation(LinearLayout.VERTICAL);
final GestureDetector mGestureDetector = new GestureDetector(new MySimpleOnGestureListener());
mScroll = new HorizontalScrollView(context);
mScroll.setLayoutParams(new LayoutParams(LayoutParams.FILL_PARENT, LayoutParams.FILL_PARENT));
mScroll.setOnTouchListener(new View.OnTouchListener() {
public boolean onTouch(View v, MotionEvent event) {
if (mGestureDetector.onTouchEvent(event)) {
return true;
} else {
return false;
}
}
});
super.addView(mScroll);
}
@Override
public void addView(View child) {
mScroll.addView(child);
}
@Override
protected void onSizeChanged(int arg0, int arg1, int arg2, int arg3) {
super.onSizeChanged(arg0, arg1, arg2, arg3);
View chield = mScroll.getChildAt(0);
if (chield != null) {
if (chield.getMeasuredWidth() > getWidth()) {
mBar.setVisibility(LinearLayout.VISIBLE);
} else {
mBar.setVisibility(LinearLayout.INVISIBLE);
}
}
}
public void previous() {
mPageActive = (mPageActive > 0) ? mPageActive - 1 : 0;
mScroll.smoothScrollTo(mPageActive * mScroll.getWidth(), 0);
}
public void next() {
int pageWidth = mScroll.getWidth();
int nextPage = (mPageActive + 1) * pageWidth;
if (nextPage - mScroll.getScrollX() <= pageWidth) {
mScroll.smoothScrollTo(nextPage, 0);
mPageActive++;
} else {
mScroll.smoothScrollTo(mScroll.getScrollX(), 0);
}
}
private class MySimpleOnGestureListener extends SimpleOnGestureListener {
@Override
public boolean onFling(MotionEvent e1, MotionEvent e2, float velocityX, float velocityY) {
if (e1 != null && e2 != null) {
if (e1.getX() - e2.getX() > 0) {
// forward...
next();
return true;
} else if (e2.getX() - e1.getX() > 0) {
// back...
previous();
return true;
}
}
return false;
}
}
public void setPage(int noOfPageToScroll ) {
int pageWidth = mScroll.getWidth(); //problem is coming in this line its coming 0 always
int nextPage = (noOfPageToScroll + 1) * pageWidth;
Log.v("trace","Pagination.setPage() called with noOfPageToScroll = "+noOfPageToScroll+"and nextPage = "+nextPage+ " and pageWidth = "+pageWidth);
mScroll.smoothScrollTo(nextPage, 0);
}
}
// -------------このjavaファイル
を使用して私の活動のイム内部ます。public void setUpViews(){
try {
TableLayout table = new TableLayout(getBaseContext());
table.setLayoutParams(new LayoutParams(LayoutParams.FILL_PARENT, LayoutParams.FILL_PARENT));
table.setGravity(Gravity.CENTER_HORIZONTAL|Gravity.CENTER_VERTICAL);
TableRow row = new TableRow(this);
row.setLayoutParams(new LayoutParams(LayoutParams.FILL_PARENT, LayoutParams.FILL_PARENT));
table.addView(row);
LayoutInflater inflater = (LayoutInflater) getBaseContext().getSystemService(Context.LAYOUT_INFLATER_SERVICE);
//throught inflator i m adding multiple dynamic Views in row
paginationLayout.addView(table);
// set pagination layout
setContentView(paginationLayout);
//here i m calling want to go to specific page so i m calling
paginationLayout.setPage(gotopageno);
//but every time is showing the first page and of scroll view and the log 06-24 16:38:39.156: VERBOSE/trace(894): setPage() called with noOfPageToScroll = gotopageno and nextPage = 0 and pageWidth = 0
//は同じくらい私はこの問題は、イムは、それがドロービューの前に呼び出されるか、他のいくつかの理由かもしれmscroll.width()== 0を得ていないということであることを理解
} catch (Exception e) {
Log.e("Error", "Problem in setUpViews() code 4 ");
e.printStackTrace();
}
}
//文法ミスを無視して助けてください。前もってありがとう