Hi Kostya, Thanks for reply.
I tried that and it is working. But the views which i draw are drawing down the scrollview.It is not drawing on top layer of scrollview. I tried with framelayout.But it is not drawing down of scrollview only. How to make it to draw on top? I tried using FrameLayout.But still same problem. Please help.It is very urgent. I have attached code for your reference. main.xml ----------------- <FrameLayout xmlns:android="http://schemas.android.com/apk/res/android" android:orientation="vertical" android:layout_width="fill_parent" android:layout_height="fill_parent" android:id="@+id/mylayout" > <FrameLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="fill_parent" android:layout_height="fill_parent" > <com.horizonscroll.TransparentPanel android:id="@+id/transparent_panel" android:layout_width="fill_parent" android:layout_height="fill_parent" android:background="#FFFFFF" > <com.horizonscroll.ScrollImageView android:id = "@+id/scrollView" android:layout_width="fill_parent" android:layout_height="wrap_content" /> </com.horizonscroll.TransparentPanel> </FrameLayout> </FrameLayout> TransparentPanel.java ------------------------------ public class TransparentPanel extends LinearLayout { private static Vector<Square> squares; private static Vector<Tile> tiles; private static Tile movingTile=null; private Paint touchPaint; public TransparentPanel(Context context, AttributeSet attrs) { super(context, attrs); init(context); } public TransparentPanel(Context context) { super(context); init(context); } private void init(Context context) { squares=Util.generateBoardSquares(); tiles=Util.generateTiles(context); } @Override public boolean onTouchEvent(MotionEvent event) { System.out.println(event.getY()); int x=(int) event.getX(); int y=(int) event.getY(); if(event.getAction() == MotionEvent.ACTION_DOWN){ for(int i=0;i<tiles.size();i++){ if(tiles.get(i).isTouched(x, y)){ movingTile=tiles.get(i); break; } } } if(event.getAction() == MotionEvent.ACTION_MOVE){ if(movingTile != null){ movingTile.setX(x); movingTile.setY(y); invalidate(); } } if(event.getAction() == MotionEvent.ACTION_UP){ if(movingTile != null){ movingTile=null; } } invalidate(); return true; } @Override protected void onDraw(Canvas canvas) { for(int i=0;i<tiles.size();i++){ Tile tile=tiles.get(i); tile.onDraw(canvas, touchPaint,tile.getX(),tile.getY()); } super.dispatchDraw(canvas); } } Activity ---------------------- public class HorizoontalScroll extends Activity { public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); requestWindowFeature(Window.FEATURE_NO_TITLE); setContentView(R.layout.main); } } 2010/11/11 Kostya Vasilyev <[email protected]> > Kavitha, > > If your intent is to let the user drag and drop game pieces from the bottom > portion of the screen to the game grid, then: > > Implement a view that subclasses ViewGroup (possibly one of its subclasses, > such as RelativeLayout or LinearLayout). Handle touch and drag events in > that view. > > Specify a transparent background for this view group so it's invisible, and > put your current views inside this one. > > This is how you can implement drag-and-drop that crosses the boundaries of > individual views. > > http://developer.android.com/guide/topics/ui/custom-components.html > > -- Kostya > > 10.11.2010 20:42, kavitha b пишет: > > > > ---------- Forwarded message ---------- > From: kavitha b <[email protected]> > Date: 2010/11/10 > Subject: Re: [android-developers] nest custom views > To: [email protected] > > > Hi Kumar, > > my requirement is > > I have a custom scrollview where i am scrolling a image. > That fills up half screen. > > I want to move images upon entire screen,including upon custom scrollview > also. > > I cannot draw bitmaps using onDraw() because I cannot draw in entire > screen. > > How to move images now. > > I wiill attach screenshot also for refernce.I want to move lettered tiles > upon board and board is scrollview here. > > My code is: > > public class HorizoontalScroll extends Activity implements > OnGestureListener > { > > private static Vector<Square> squares; > private static Vector<Tile> tiles; > private Tile tile; > > > > > > > @Override > public void onCreate(Bundle savedInstanceState) > { > super.onCreate(savedInstanceState); > > > setContentView(R.layout.main); > > squares=Util.generateBoardSquares(); > tiles=Util.generateTiles(this); > > > > > } > > } > > > main.xml looks like this > > <AbsoluteLayout xmlns:android="http://schemas.android.com/apk/res/android" > android:orientation="vertical" > android:layout_width="fill_parent" > android:layout_height="fill_parent" > android:id="@+id/mylayout" > > > <com.horizonscroll.ScrollImageView > android:id = "@+id/scrollView" > android:layout_width="fill_parent" > android:layout_height="wrap_content" > > /> > </AbsoluteLayout> > > > And ScrollImageView.java > public class ScrollImageView extends View { > private final int DEFAULT_PADDING = 0; > private Display mDisplay; > private Bitmap mImage; > private Bitmap mTile; > > > /* Current x and y of the touch */ > private float mCurrentX = 0; > private float mCurrentY = 0; > > > private float mTotalX = 0; > private float mTotalY = 0; > > /* The touch distance change from the current touch */ > private float mDeltaX = 0; > private float mDeltaY = 0; > > > int mDisplayWidth; > int mDisplayHeight; > int mPadding; > > > public ScrollImageView(Context context) { > super(context); > initScrollImageView(context); > } > public ScrollImageView(Context context, AttributeSet attributeSet) { > super(context); > initScrollImageView(context); > } > > private void initScrollImageView(Context context) { > mDisplay = > ((WindowManager)context.getSystemService(Context.WINDOW_SERVICE)).getDefaultDisplay(); > mPadding = DEFAULT_PADDING; > mImage=BitmapFactory.decodeResource(getResources(), > R.drawable.woodstandardboard); > mTile=BitmapFactory.decodeResource(getResources(), > R.drawable.woodtile); > } > > @Override > protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) > { > int width = measureDim(widthMeasureSpec, mDisplay.getWidth()); > int height = measureDim(heightMeasureSpec, mDisplay.getHeight()); > setMeasuredDimension(width, height-100); > } > > > private int measureDim(int measureSpec, int size) { > int result = 0; > int specMode = MeasureSpec.getMode(measureSpec); > int specSize = MeasureSpec.getSize(measureSpec); > > > if (specMode == MeasureSpec.EXACTLY) { > result = specSize; > } else { > result = size; > if (specMode == MeasureSpec.AT_MOST) { > result = Math.min(result, specSize); > } > } > return result; > } > > public Bitmap getImage() { > return mImage; > } > > public void setImage(Bitmap image) { > mImage = image; > } > > > public int getPadding() { > return mPadding; > } > > > public void setPadding(int padding) { > this.mPadding = padding; > } > > > private static int boardX=0; > private static int boardY=0; > > @Override > public boolean onTouchEvent(MotionEvent event) { > if (event.getAction() == MotionEvent.ACTION_DOWN) { > mCurrentX = event.getRawX(); > mCurrentY = event.getRawY(); > > > } > else if (event.getAction() == MotionEvent.ACTION_MOVE) { > float x = event.getRawX(); > float y = event.getRawY(); > > > // Update how much the touch moved > mDeltaX = x - mCurrentX; > mDeltaY = y - mCurrentY; > > > > mCurrentX = x; > mCurrentY = y; > > invalidate(); > } > // Consume event > return true; > } > > > @Override > protected void onDraw(Canvas canvas) { > if (mImage == null) { > return; > } > > > float newTotalX = mTotalX + mDeltaX; > // Don't scroll off the left or right edges of the bitmap. > if (mPadding > newTotalX && newTotalX > getMeasuredWidth() - > mImage.getWidth() - mPadding) > mTotalX += mDeltaX; > > > float newTotalY = mTotalY + mDeltaY; > // Don't scroll off the top or bottom edges of the bitmap. > if (mPadding > newTotalY && newTotalY > getMeasuredHeight() - > mImage.getHeight() - mPadding) > mTotalY += mDeltaY; > > Paint paint = new Paint(); > canvas.drawBitmap(mImage, mTotalX, mTotalY, paint); > canvas.drawBitmap(mTile, mTotalX+50, mTotalY+500, paint); > canvas.drawBitmap(mTile, mTotalX+50, mTotalY+50, paint); > > } > } > > > > > On Wed, Nov 10, 2010 at 10:29 PM, Kumar Bibek <[email protected]>wrote: > >> Well, if you mean nesting View classes, that's not possible. You can nest >> views/viewgroups if the parent is a ViewGroup. >> >> 2010/11/10 kavitha b <[email protected]> >> >> I want nest 2 custom views through code. >>> >>> I didnt understand how to do it. >>> >>> Please provide any example. >>> >>> 2010/11/10 Kostya Vasilyev <[email protected]> >>> >>>> Well, subclass ViewGroup or one of its subclasses for the outer view, >>>> and View or one of its subclasses for the inner view. Then create them >>>> nested, either with xml, or from code. >>>> >>>> -- >>>> Kostya Vasilyev -- http://kmansoft.wordpress.com >>>> >>>> 10.11.2010 19:04 пользователь "kavitha b" <[email protected]> >>>> написал: >>>> >>>> >>>> Can you please provide me an example of that. >>>> >>>> I want to nest custom views,,,i mean outside one custom view and inside >>>> that another custom view.but how to draw a view within another? >>>> >>>> It is very very urgent. >>>> >>>> Please help. >>>> >>>> 2010/11/10 Kostya Vasilyev <[email protected]> >>>> >>>> >>>> > >>>> > Sure, as long as the enclosing view is a ViewGroup (custom or not). >>>> > >>>> > -- >>>> > Kostya Vasilyev --... >>>> >>>> >>>> >>>> >>>> -- >>>> You received this message because you are subscribed to the Google >>>> Groups "Android Developers... >>>> >>>> -- >>>> You received this message because you are subscribed to the Google >>>> Groups "Android Developers" group. >>>> To post to this group, send email to >>>> [email protected] >>>> To unsubscribe from this group, send email to >>>> [email protected]<android-developers%[email protected]> >>>> For more options, visit this group at >>>> http://groups.google.com/group/android-developers?hl=en >>>> >>> >>> -- >>> You received this message because you are subscribed to the Google >>> Groups "Android Developers" group. >>> To post to this group, send email to [email protected] >>> To unsubscribe from this group, send email to >>> [email protected]<android-developers%[email protected]> >>> For more options, visit this group at >>> http://groups.google.com/group/android-developers?hl=en >> >> >> >> >> -- >> Kumar Bibek >> http://techdroid.kbeanie.com >> http://www.kbeanie.com >> >> >> -- >> You received this message because you are subscribed to the Google >> Groups "Android Developers" group. >> To post to this group, send email to [email protected] >> To unsubscribe from this group, send email to >> [email protected]<android-developers%[email protected]> >> For more options, visit this group at >> http://groups.google.com/group/android-developers?hl=en >> > > > -- > You received this message because you are subscribed to the Google > Groups "Android Developers" group. > To post to this group, send email to [email protected] > To unsubscribe from this group, send email to > [email protected] > For more options, visit this group at > http://groups.google.com/group/android-developers?hl=en > > > > -- > Kostya Vasilyev -- WiFi Manager + pretty widget -- > http://kmansoft.wordpress.com > > -- > You received this message because you are subscribed to the Google > Groups "Android Developers" group. > To post to this group, send email to [email protected] > To unsubscribe from this group, send email to > [email protected]<android-developers%[email protected]> > For more options, visit this group at > http://groups.google.com/group/android-developers?hl=en > -- You received this message because you are subscribed to the Google Groups "Android Developers" group. To post to this group, send email to [email protected] To unsubscribe from this group, send email to [email protected] For more options, visit this group at http://groups.google.com/group/android-developers?hl=en

