Note that there are some explanatory texts on larger screens.

plurals
  1. POProblem in HorizontaScrollView and swiping the screen
    primarykey
    data
    text
    <p>In my code i m implementing swipe using the HorizontalScrollView for that i got a proper working code , its working fine to swipe left or right now my problem is i wand to show a dynamic page no. for that i added some extra code in that but its not working the code is below</p> <pre><code>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() &gt; getWidth()) { mBar.setVisibility(LinearLayout.VISIBLE); } else { mBar.setVisibility(LinearLayout.INVISIBLE); } } } public void previous() { mPageActive = (mPageActive &gt; 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() &lt;= 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 &amp;&amp; e2 != null) { if (e1.getX() - e2.getX() &gt; 0) { // forward... next(); return true; } else if (e2.getX() - e1.getX() &gt; 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); } } </code></pre> <p>//-------------inside the my activity i m using this java file</p> <p>public void setUpViews(){ </p> <pre><code> 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 </code></pre> <p>// as much i understand the problem is that i m not getting the mscroll.width() == 0 it is called before draw view or may be some other reason </p> <pre><code> } catch (Exception e) { Log.e("Error", "Problem in setUpViews() code 4 "); e.printStackTrace(); } } </code></pre> <p>//Please help me and ignore any grammer mistake. Thanks in advance </p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload