Android Custom ScrollView containing LinearLayout with Custom Views -
i having lots of problems, both scrolling, , picking touch signals in correct places.
basically application is:
viewpager -> fragment -> scrollview -> linearlayout -> lots of dynamically added customer view objects
the fragment xml:
<linearlayout xmlns:android="http://schemas.android.com/apk/res/android" android:id="@+id/transaction_view" android:layout_width="fill_parent" android:layout_height="fill_parent" android:orientation="vertical" > <button android:id="@+id/add_new_transaction" android:layout_width="fill_parent" android:layout_height="wrap_content" android:text="@string/addnewtransaction" /> <com.company.application.transactionscroller android:id="@+id/transaction_scroller" android:layout_width="fill_parent" android:layout_height="match_parent" android:fillviewport="true" > <com.company.application.transactiongroup android:id="@+id/transaction_list" android:layout_width="fill_parent" android:layout_height="wrap_content" android:layout_gravity="fill" android:orientation="vertical" > </com.company.application.transactiongroup> </com.company.application.transactionscroller> </linearlayout>
where transactionscroller scrollview, transactiongroup linearlayout. view object custom drawn, , following:
@override protected void onmeasure( int widthmeasurespec, int heightmeasurespec ) { // try width based on our minimum setmeasureddimension( width, height ) ; } @override public boolean ontouchevent( motionevent event ) { toast.maketext( getcontext(), "grid", toast.length_short ).show() ; return true ; } public void draw( canvas canvas ) { if( tmpbmp.isrecycled() || tmpbmp.getwidth()!=canvas.getwidth() || tmpbmp.getheight()!=canvas.getheight() ) { tmpbmp.recycle(); tmpbmp = bitmap.createbitmap( canvas.getwidth(), canvas.getheight(), config.argb_8888 ) ; c.setbitmap( tmpbmp ) ; } //clear previous drawings c.drawcolor( color.transparent, mode.clear ) ; // draw background c.drawrect( spacing, top, width - spacing , bottom, newpaint ) ; // draw lines for( line line : linelist ) { c.drawline( line.x1, line.y1, line.x2, line.y2, paint ) ; } canvas.drawbitmap( tmpbmp, 0, 0, null ) ; canvas.drawtext( string.valueof( amount ), left, top + ( bottom - top ) /2 , paint); canvas.drawbitmap( ( ( bitmapdrawable )mainactivity.iconlist[ index ].getdrawable() ).getbitmap(), left + mainactivity.iconlist[ index ].getwidth(), top + ( bottom - top ) /2, paint ) ; }
1) firstly, trying capture touch , drag events in custom view object. have been able capture events in scrollview, down event in linearlayout, , nothing in custom view.
in scrolview:
setontouchlistener( new ontouchlistener() { @override public boolean ontouch( view view, motionevent event ) { // called when touched outside scrollview if( event.getaction() == android.view.motionevent.action_down ) { toast.maketext( getcontext(), "s_down", toast.length_short ).show() ; return false ; } else if( event.getaction() == android.view.motionevent.action_up ) { toast.maketext( getcontext(), "s_up", toast.length_short ).show() ; return false ; } return false; } } ) ;
which both called in scrollview. same thing in linearlayout, down event gets captured , in custom view, nothing captured. have tried setting focusable, clickable etc.
any ideas?
2) secondly, scrollview not scrolling when has custom view objects in it. when filled else e.g. buttons. can see above, using onmeasure(), , have tried hardcoding these values no avail.
thanks in advance. jack
Comments
Post a Comment