Search Results

Search found 104 results on 5 pages for 'ondraw'.

Page 2/5 | < Previous Page | 1 2 3 4 5  | Next Page >

  • how to display complete Bitmap in android using Canvas?

    - by UMMA
    friends, i am using following onDraw method to display bitmap on screen. @Override public void onDraw(Canvas canvas) { Bitmap _scratch = BitmapFactory.decodeResource(getResources(), R.drawable.icon2); //ImageView img= new ImageView(Tutorial2D.this); //img.setImageBitmap(_scratch); canvas.drawColor(Color.BLACK); canvas.drawBitmap(_scratch, 0, 0, null); } image is displayed on the screen but some part because android screen is small how can i display complete image in whole android screen? can i set ScaleType of image to fitxy in canvas ? or can i add android layout image to this canvas so that i could set fitxy property or image there as i have commented the code? any help would be appreciated.

    Read the article

  • How to get ImageButton size within Android GridView?

    - by wufoo
    I'm subclassing ImageButton in order to draw lines on it and trying to figure out where the actual button coordinates are within my gridview. I am using onGlobalLayout to setup Top, Bottom, Right and Left, but these seem to be for the actual "square" within the grid, and not the actual button (see image). The purple lines are drawn in myImageButton.onDraw() using coords gathered from myImageButton.onGlobalLayout(). I thought these would be for the button, but they seem to be from something else. Not sure what. I'd like the purple lines to match the outline of the button so the lines I draw appear on the button and not just floating out in the LinearLayout somewhere. The light blue is the background color of the vertical LinearLayout holding the Textview (for the number) and myImageButton. Any way to get the actual button size? XML Layout: <FrameLayout xmlns:android="http://schemas.android.com/apk/res/android" android:id="@+id/lay_cellframe" android:layout_width="fill_parent" android:layout_height="fill_parent" > <LinearLayout android:layout_width="fill_parent" android:layout_height="fill_parent" android:gravity="fill_vertical|fill_horizontal" android:orientation="vertical" > <TextView android:id="@+id/tv_cell" android:layout_width="fill_parent" android:layout_height="wrap_content" android:layout_margin="2dp" android:gravity="center" android:text="TextView" android:textSize="10sp" /> <com.example.icaltest2.myImageButton android:id="@+id/imageButton1" android:layout_width="fill_parent" android:layout_height="fill_parent" android:layout_gravity="center" android:layout_margin="0dp" android:adjustViewBounds="false" android:background="@android:drawable/btn_default" android:scaleType="fitXY" android:src="@android:color/transparent" /> </LinearLayout> </FrameLayout> myImageButton.java public myImageButton (Context context, AttributeSet attrs) { super (context, attrs); mBounds = new Rect(); ViewTreeObserver vto = this.getViewTreeObserver (); vto.addOnGlobalLayoutListener (ogl); Log.d (TAG, "myImageButton"); } ... OnGlobalLayoutListener ogl = new OnGlobalLayoutListener() { @Override public void onGlobalLayout () { Rect b = getDrawable ().getBounds (); mBtnTop = b.centerY () - (b.height () / 2); mBtnBot = b.centerY () + (b.height () / 2); mBtnLeft = b.centerX () - (b.width () / 2); mBtnRight = b.centerX () + (b.width () / 2); } }; ... @Override protected void onDraw (Canvas canvas) { super.onDraw (canvas); Paint p = new Paint (); p.setStyle (Paint.Style.STROKE); p.setStrokeWidth (1); p.setColor (Color.MAGENTA); canvas.drawCircle (mBtnLeft, mBtnTop, 2, p); canvas.drawCircle (mBtnLeft, mBtnBot, 2, p); canvas.drawCircle (mBtnRight, mBtnTop, 2, p); canvas.drawCircle (mBtnRight, mBtnBot, 2, p); canvas.drawRect (mBtnLeft, mBtnTop, mBtnRight, mBtnBot, p); }

    Read the article

  • Android SurfaceView/Canvas flickering after trying to clear it

    - by Mark D
    So I am trying to clear the Canvas using canvas.drawColor(Color.BLACK) but if I just call this once, the display flickers and displays the old drawing which should have been covered up by the drawColor. Here is the important bits of my code - public void update() { //This method is called by a Thread Canvas canvas = holder.lockCanvas(null); if (canvas != null) { onDraw(canvas); } holder.unlockCanvasAndPost(canvas); } @Override protected void onDraw(Canvas canvas) { if (toClear) { canvas.drawColor(Color.BLACK); //if this is not set to change back to false, it does not flicker toClear = false; } //Draw some objects that are moving around } public void clearScreen() { //This method is called when the user pressed a button toClear = true; } After Googling around a litte, I heard about double buffering but came to the understanding that lockCanvas() and unlockCanvasAndPost() should handle this for me. What is going wrong here?

    Read the article

  • How do I make this rendering thread run together with the main one?

    - by funk
    I'm developing an Android game and need to show an animation of an exploding bomb. It's a spritesheet with 1 row and 13 different images. Each image should be displayed in sequence, 200 ms apart. There is one Thread running for the entire game: package com.android.testgame; import android.graphics.Canvas; public class GameLoopThread extends Thread { static final long FPS = 10; // 10 Frames per Second private final GameView view; private boolean running = false; public GameLoopThread(GameView view) { this.view = view; } public void setRunning(boolean run) { running = run; } @Override public void run() { long ticksPS = 1000 / FPS; long startTime; long sleepTime; while (running) { Canvas c = null; startTime = System.currentTimeMillis(); try { c = view.getHolder().lockCanvas(); synchronized (view.getHolder()) { view.onDraw(c); } } finally { if (c != null) { view.getHolder().unlockCanvasAndPost(c); } } sleepTime = ticksPS - (System.currentTimeMillis() - startTime); try { if (sleepTime > 0) { sleep(sleepTime); } else { sleep(10); } } catch (Exception e) {} } } } As far as I know I would have to create a second Thread for the bomb. package com.android.testgame; import android.graphics.Bitmap; import android.graphics.Canvas; import android.graphics.Rect; public class Bomb { private final Bitmap bmp; private final int width; private final int height; private int currentFrame = 0; private static final int BMPROWS = 1; private static final int BMPCOLUMNS = 13; private int x = 0; private int y = 0; public Bomb(GameView gameView, Bitmap bmp) { this.width = bmp.getWidth() / BMPCOLUMNS; this.height = bmp.getHeight() / BMPROWS; this.bmp = bmp; x = 250; y = 250; } private void update() { currentFrame++; new BombThread().start(); } public void onDraw(Canvas canvas) { update(); int srcX = currentFrame * width; int srcY = height; Rect src = new Rect(srcX, srcY, srcX + width, srcY + height); Rect dst = new Rect(x, y, x + width, y + height); canvas.drawBitmap(bmp, src, dst, null); } class BombThread extends Thread { @Override public void run() { try { sleep(200); } catch(InterruptedException e){ } } } } The Threads would then have to run simultaneously. How do I do this?

    Read the article

  • Basic Android game loop having issues

    - by WillDaBeast509
    I've set up a very basic game loop that should draw a circle, run 100 times, then draw another. I also have a text field that should display how many times the loop has ran. However, the screen seems to not update. It displays a different value for the tick count (different each time the app is ran) and simply stays there. After exiting the app, I get an error saying "Unfortunately, MyApp has stopped." Here is the relevant code: DrawView public class DrawView extends SurfaceView implements SurfaceHolder.Callback { Paint p = new Paint(); MainThread thread; private int y=0; public DrawView(Context c) { super(c); thread = new MainThread(this, getHolder()); thread.running = true; getHolder().addCallback(this); setFocusable(true); } public void draw(Canvas c) { if(c==null) return; //super.onDraw(c); c.drawColor(Color.WHITE); p.setColor(Color.RED); p.setTextSize(32); p.setTypeface(Typeface.SANS_SERIF); c.drawCircle(getWidth()/2-100,getHeight()/2, 50, p); c.drawText("y = " + y, 50, 50, p); if(y>=100) { Log.i("DRAW", "drawing circle"); c.drawCircle(getWidth()/2+100,getHeight()/2, 50, p); } else y++; Log.i("INFO", "y = " + y); } @Override public boolean onTouchEvent(MotionEvent event) { return true; } public void onDraw(Canvas c){} public void surfaceCreated(SurfaceHolder p1) { thread.start(); } public void surfaceChanged(SurfaceHolder p1, int p2, int p3, int p4) { // TODO: Implement this method } public void surfaceDestroyed(SurfaceHolder p1) { thread.running = false; boolean retry = true; while (retry) { try { thread.join(); retry = false; } catch (InterruptedException e) { Log.i("EX", "cathing exception"); } } } } MainThread public class MainThread extends Thread { private DrawView page; private SurfaceHolder holder; public boolean running; public MainThread(DrawView p, SurfaceHolder h) { super(); page = p; holder = h; } @Override public void run() { while(running) { Canvas c = holder.lockCanvas(); page.draw(c); holder.unlockCanvasAndPost(c); } } } Here is an example log outupt: http://pastebin.com/tM9dUPuk It counts the number of ticks correctly and should draw the second circle, but the screen looks like its not updating. After closing the app, the log continues to run and keep outputting "y = 100 drawing circle" until it crashes and shows the error report. What is going on and how can I fix these two problems?

    Read the article

  • Android how to match text with images by pointing text and images with lines

    - by Shirisha
    I am trying to create app which is match text with appropriate images by pointing with line. I want to create app exactly same which is shown in the below image: can any one please give me an idea? This is my main class: public class MatchActivity extends Activity { ArrayAdapter<String> listadapter; float x1; float y1; float x2; float y2; @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); String[] s1 = { "smiley1", "smiley2", "smiley3" }; ListView lv = (ListView) findViewById(R.id.text_list); ArrayList<String> list = new ArrayList<String>(); list.addAll(Arrays.asList(s1)); listadapter = new ArrayAdapter<String>(this, R.layout.rowtext, s1); lv.setAdapter(listadapter); GridView gv = (GridView) findViewById(R.id.image_list); gv.setAdapter(new ImageAdapter(this)); lv.setOnItemClickListener(new OnItemClickListener() { public void onItemClick(AdapterView<?> arg0, View v, int arg2, long arg3){ x1=v.getX(); y1=v.getY(); Log.d("list","text positions x1:"+x1+" y1:"+y1); } }); gv.setOnItemClickListener(new OnItemClickListener() { public void onItemClick(AdapterView<?> arg0, View v, int arg2, long arg3){ DrawView draw=new DrawView(MatchActivity.this); x2=v.getX(); y2=v.getY(); draw.position1.add(x1); draw.position1.add(y1); draw.position2.add( x2); draw.position2.add(y2); Log.d("list","image positions x2:"+x2+" y2:"+y2); LinearLayout ll=LinearLayout)findViewById(R.id.draw_line); ll.addView(draw); } }); } } This is my drawing class to draw a line: public class DrawView extends View { Paint paint = new Paint(); private List<Float> position1=new ArrayList<Float>(); private List<Float> position2=new ArrayList<Float>();; public DrawView(Context context) { super(context); invalidate(); Log.d("drawview","In DrawView class position1:"+position1+" position2:"+position2) ; } @Override public void onDraw(Canvas canvas) { super.onDraw(canvas); Log.d("on draw","IN onDraw() position1:"+position1+" position2:"+position2); assert position1.size() == position2.size(); for (int i = 0; i < position1.size(); i += 2) { float x1 = position1.get(i); float y1 = position1.get(i + 1); float x2 = position2.get(i); float y2 = position2.get(i + 1); paint.setColor(Color.BLACK); paint.setStrokeWidth(3); canvas.drawLine(x1,y1, x2,y2, paint); } } } Thanks in advance .

    Read the article

  • How to draw an overlay on a SurfaceView used by Camera on Android?

    - by Cristian Castiblanco
    I have a simple program that draws the preview of the Camera into a SurfaceView. What I'm trying to do is using the onPreviewFrame method, which is invoked each time a new frame is drawn into the SurfaceView, in order to execute the invalidate method which is supposed to invoke the onDraw method. In fact, the onDraw method is being invoked, but nothing there is being printed (I guess the camera preview is overwriting the text I'm trying to draw). This is a simplify version of the SurfaceView subclass I have: public class Superficie extends SurfaceView implements SurfaceHolder.Callback { SurfaceHolder mHolder; public Camera camera; Superficie(Context context) { super(context); mHolder = getHolder(); mHolder.addCallback(this); mHolder.setType(SurfaceHolder.SURFACE_TYPE_PUSH_BUFFERS); } public void surfaceCreated(final SurfaceHolder holder) { camera = Camera.open(); try { camera.setPreviewDisplay(holder); camera.setPreviewCallback(new PreviewCallback() { public void onPreviewFrame(byte[] data, Camera arg1) { invalidar(); } }); } catch (IOException e) {} } public void invalidar(){ invalidate(); } public void surfaceChanged(SurfaceHolder holder, int format, int w, int h) { Camera.Parameters parameters = camera.getParameters(); parameters.setPreviewSize(w, h); camera.setParameters(parameters); camera.startPreview(); } @Override public void draw(Canvas canvas) { super.draw(canvas); // nothing gets drawn :( Paint p = new Paint(Color.RED); canvas.drawText("PREVIEW", canvas.getWidth() / 2, canvas.getHeight() / 2, p); } }

    Read the article

  • Help with Android LinearLayout or RelativeLayout

    - by PeEll
    I need to create two views programmatically (because I need to access the ondraw of one of the views). For some reason, no matter what I do to add the views to the contentview, they don't show up vertically stacked, one below the other. I can do it just fine using the XML using a RelativeLayout and layout positioning, but with the XML I can't create a view object and overload the ondraw method. What am I doing wrong with the programmatic approach, and how do I solve this problem? LinearLayout mLinearLayout; public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); // Create a LinearLayout in which to add the ImageView mLinearLayout = new LinearLayout(this); TextView tv = new TextView(this); tv.setBackgroundColor(0xff333333); tv.setText("Enter your member number:"); tv.setLayoutParams(new ViewGroup.LayoutParams(LayoutParams.FILL_PARENT,LayoutParams.WRAP_CONTENT)); DrawableView i = new DrawableView(this); i.layout(0,40,0,0); i.setLayoutParams(new Gallery.LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT)); mLinearLayout.addView(tv); mLinearLayout.addView(i,300,300); setContentView(mLinearLayout); }

    Read the article

  • using ontouch to zoom in

    - by user357032
    i have used some sample code and am trying to tweak it to let me allow the user to touch the screen and zoom in the code runs fine with no errors but when i touch the screen nothing happens package com.thomas.zoom; import android.content.Context; import android.graphics.Canvas; import android.graphics.drawable.Drawable; import android.view.KeyEvent; import android.view.MotionEvent; import android.view.View; public class Zoom extends View { private Drawable image; private int zoomControler=20; public Zoom(Context context) { super(context); image=context.getResources().getDrawable(R.drawable.icon); setFocusable(true); } @Override protected void onDraw(Canvas canvas) { // TODO Auto-generated method stub super.onDraw(canvas); //here u can control the width and height of the images........ this line is very important image.setBounds((getWidth()/2)-zoomControler, (getHeight()/2)-zoomControler, (getWidth()/2)+zoomControler, (getHeight()/2)+zoomControler); image.draw(canvas); } public boolean onTouch(int action, MotionEvent event) { action= event.getAction(); if(action == MotionEvent.ACTION_DOWN){ zoomControler+=10; } invalidate(); return true; } }

    Read the article

  • How to use RelativeLayout to make a custom component on Android

    - by Styggentorsken
    I'm trying to make a custom component based on buttons without having to deal with all the layout myself. The problem is that i can't find a way to make use of RelativeLayout to draw the thing. This is my latest attempt. A bitmap is returned by layoutManager.getDrawingCache(), but it does not show any buttons. canvas.drawColor(...) however works. public class MyView extends View { Button myButton; RelativeLayout layoutManager; public MyView(Context context) { super(context); initMyView(); } public MyView(Context context, AttributeSet attrs) { super(context); initMyView(); // ... } public void initMyView() { layoutManager = new RelativeLayout(getContext()); } @Override protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) { setMeasuredDimension( MeasureSpec.getSize(measureSpec), MeasureSpec.getSize(measureSpec) ); } @Override protected void onDraw(Canvas canvas) { super.onDraw(canvas); myButton = new Button(layoutManager.getContext()); myButton.setVisibility(VISIBLE); myButton.setDrawingCacheEnabled(true); layoutManager.addView(myButton); layoutManager.setDrawingCacheEnabled(true); layoutManager.layout(0, 0, 150, 150); layoutManager.setVisibility(VISIBLE); layoutManager.buildDrawingCache(); layoutManager.draw(canvas); canvas.drawBitmap(layoutManager.getDrawingCache(), 0.0f, 0.0f, null); } }

    Read the article

  • ImageViews sometimes not displaying in FrameLayout activity

    - by Ken
    The top level layout in my activity is a framelayout. I have completed, debugged and tested this app and it works exactly like it should in all respects on my g1 and on various emulators. But on 3.7-inch displays running 2.1+, some imageviews packed in a linearlayout are periodically not visible. I know that they are there because you can touch and drag them with effect in the app. So I assume somehow they have gotten under the SurfaceView that is the main component of the app. This is apparently so even though the SurfaceView is declared in the xml prior to the LinearLayout. However, the ImageViews IN the LinearLayout are added programmatically towards the end of onCreate(). Framelayout stacks everything that is added to it, one on top of the other--the only way you will see more than one child of a frame layout is if they are smaller than the screen and are placed apart from eachother. Oddly, sometimes the imageviews ARE visible--it is random. Anyway, I've been trying to combat this with framelayout.bringChildToFront(View v) on the linearlayout without success. I wonder if anyone has any insight into how the behavior could be random like that, and how I should code these imageviews to keep this from happening, and why the problem appears only to occur on 3.7 vs 3.2 inch screens (as it happens, the two 3.2-inch screens were both htc, so vendor might be factor too). [edit] Actually, I've determined that this is a 2.2 issue, not a screen size (or even vendor) issue. Can't ensure that ImageViews added to a framelayout with a SurfaceView in it will appear on top of the surfaceview. I ran some tests in the respective onDraw() methods and the imageviews are 'visible' (0), and nothing does anything to the alpha of the drawables, which are there as well at ondraw(). [/edit] Any insight would be welcomed. Ken T.

    Read the article

  • Android lifecycle of thread-based game

    - by ehehhh
    I ran into a bit of trouble while trying to get my game to work correctly after being put to the background by the user or a phone call for example. My app has a SurfaceView class called GameView, which has the onDraw() method to do all the necessary drawing for my game and two threads - one for calling the onDraw() and one for doing the necessary calculations for the game's logic. I succesfully implemented onPause() and onResume(). (I paused both threads when back button was pressed and resumed them after user cancelled in the AlertDialog.) Now I would like to have the game paused the same way when onStop() gets called. I put both threads on pause and saved my characters location in the savedInstanceState, but when I start my app again, no method gets called (I checked with Logcat). I believe onRestart() should be called first, then onStart() and then onResume(), but none of that happens. What am I doing wrong? (Didn't include any code, because it seems to be a problem of me not understanding the lifecycle, not a problem in code. If it seems necessary, I'll post the parts you request.)

    Read the article

  • Android game scrolling background

    - by Stevanicus
    Hi There, I'm just trying to figure out the best approach for running a scolling background on an android device. The method I have so far.... its pretty laggy. I use threads, which I believe is not the best bet for android platforms @Override public void run() { // Game Loop while(runningThread){ //Scroll background down bgY += 1; try { this.postInvalidate(); t.sleep(10); } catch (Exception e) { // TODO Auto-generated catch block e.printStackTrace(); } } } where postinvalidate in the onDraw function simply pushings the background image down canvas.drawBitmap(backgroundImage, bgX, bgY, null); Thanks in advance

    Read the article

  • how to display IBitmapImage on CDC

    - by tommyk
    What is the best way to display IBitmapImage on a device context. I am using Windows CE 6.0. void CImaginingTestView::OnDraw(CDC* pDC) { CImaginingTestDoc* pDoc = GetDocument(); ASSERT_VALID(pDoc); IBitmapImage* pBitmapImage = pDoc->GetBitmapImage(); if (pBitmapImage) { // how to draw my bitmap on a pDC ?? } }

    Read the article

  • Possible to do rounded corners in custom Progressbar progressDrawable?

    - by b-ryce
    I have a progress bar that is supposed to look like the attached image: And I've made it a long way. I'm very close the only part that isn't working is the rounded corners for the progressDrawable. Here is what mine looks like. (Notice, circled in red, that the fill inside the white outline does not have rounded corners): So, I've found a couple of ways to make this work when the progress bar is colored in with a shape, gradient, or color. BUT, I can't get it with an image as the progressDrawable. Here is my class that extends ProgressBar public class RoundedProgressBar extends ProgressBar{ private Paint paint; public RoundedProgressBar(Context context) { super(context); setup(); } public RoundedProgressBar(Context context, AttributeSet attrs) { super(context, attrs); setup(); } public RoundedProgressBar(Context context, AttributeSet attrs, int defStyle) { super(context, attrs, defStyle); setup(); ; } protected void setup() { paint = new Paint(); } @Override protected synchronized void onDraw(Canvas canvas) { // First draw the regular progress bar, then custom draw our text super.onDraw(canvas); paint.setColor(Color.WHITE); paint.setStyle(Paint.Style.STROKE); RectF r = new RectF(0,0,getWidth()-1,getHeight()-1); canvas.drawRoundRect(r,getHeight()/2,getHeight()/2, paint); } } Here is my selector: <layer-list xmlns:android="http://schemas.android.com/apk/res/android" > <item android:id="@android:id/background" android:drawable="@drawable/slider_track" /> <item android:id="@android:id/secondaryProgress" android:drawable="@drawable/slider_track" /> <item android:id="@android:id/progress" android:drawable="@drawable/slider_track_progress" /> </layer-list> Here are the images used in the selector: slider_track- slider_track_progress- Here is where I embed my progressbar in the layout for my activity <com.android.component.RoundedProgressBar android:id="@+id/player_hp_bar" android:layout_width="fill_parent" android:layout_height="36dip" android:layout_marginLeft="30dip" android:layout_marginRight="30dip" android:max="100" style="?android:attr/progressBarStyleHorizontal" android:progressDrawable="@drawable/slider_layer_list" android:progress="20" android:maxHeight="12dip" android:minHeight="12dip" /> Anyone know how to make this work?

    Read the article

  • Android Mapview panning and zooming too slow........

    - by Pratap S
    I've developed a GPS app in which i record the user roots and show it on the map.......but Panning around on the map when reviewing my route is painfully slow, it takes at least 4 or 5 seconds for the map to respond the finger swipes...... I've overridden the onDraw() method and drawing the lines to show the routes......is there any better way to do this so that panning becomes faster as in "MyTracks"........... Thank you all..... Pratap S.

    Read the article

  • How can I scroll my custom view? I want to see the shapes drawn over the bounds of the screen

    - by antonio Musella
    I have a Custom view ... package nan.salsa.goal.customview; import android.R; import android.content.Context; import android.graphics.Canvas; import android.graphics.drawable.ShapeDrawable; import android.graphics.drawable.shapes.RectShape; import android.util.AttributeSet; import android.util.Log; import android.view.View; public class DayView extends View { private static String TAG="DayView"; private ShapeDrawable mDrawable; public DayView(Context context) { super(context); } public DayView(Context context, AttributeSet attrs) { super(context, attrs); init(); } public DayView(Context context, AttributeSet attrs, int defStyle) { super(context, attrs, defStyle); init(); } public void init() { int x = 10; int y = 10; mDrawable = new ShapeDrawable(new RectShape()); mDrawable.getPaint().setColor(Color.GREEN); mDrawable.setBounds(x, y, x + (width - (x * 2)), y + (height - (y*2))); mDrawable.draw(canvas); for (int i = 1; i < 30; i++) { boxDrawable = new ShapeDrawable(new RectShape()); boxDrawable.setBounds(x + x , y + (100 * i) , x + (width - ((x + x) * 2)), y + (100 * i) + 50); boxDrawable.getPaint().setColor(Color.RED); boxDrawable.draw(canvas); } } @Override protected void onDraw(Canvas canvas) { // TODO Auto-generated method stub super.onDraw(canvas); setBackgroundColor(R.color.black); mDrawable.draw(canvas); } } with this simple configuration file : <?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:orientation="vertical" android:layout_width="fill_parent" android:layout_height="fill_parent" android:background="#E06F00"> <nan.salsa.goal.customview.DayView android:id="@+id/dayView" android:layout_height="match_parent" android:layout_width="fill_parent" /> </LinearLayout> In my view I want to scroll to see the shapes drawn over the bounds of the screen .. How I can do it? Regards, Antonio Musella

    Read the article

  • Vertical Seek not progress value not showing on MainActivity textView

    - by Raju Gujarati
    I am try to display the progress value of the seekBar but when it comes to the execution, there is no update on the value being display on the TextView. I wonder what alternatives than putting two classes onto one big class in order to archive this aim ? The below is my code VerticalSeekBar.java package com.example.imagerotation; import android.content.Context; import android.graphics.Canvas; import android.util.AttributeSet; import android.view.MotionEvent; import android.widget.SeekBar; import android.widget.Toast; public class VerticalSeekBar extends SeekBar { public VerticalSeekBar(Context context) { super(context); } public VerticalSeekBar(Context context, AttributeSet attrs, int defStyle) { super(context, attrs, defStyle); } public VerticalSeekBar(Context context, AttributeSet attrs) { super(context, attrs); } protected void onSizeChanged(int w, int h, int oldw, int oldh) { super.onSizeChanged(h, w, oldh, oldw); } @Override protected synchronized void onMeasure(int widthMeasureSpec, int heightMeasureSpec) { super.onMeasure(heightMeasureSpec, widthMeasureSpec); setMeasuredDimension(getMeasuredHeight(), getMeasuredWidth()); } protected void onDraw(Canvas c) { c.rotate(-90); c.translate(-getHeight(), 0); super.onDraw(c); } @Override public boolean onTouchEvent(MotionEvent event) { if (!isEnabled()) { return false; } switch (event.getAction()) { case MotionEvent.ACTION_DOWN: case MotionEvent.ACTION_MOVE: case MotionEvent.ACTION_UP: int progress = getMax() - (int) (getMax() * event.getY() / getHeight()); setProgress(progress); onSizeChanged(getWidth(), getHeight(), 0, 0); //Toast.makeText(getContext(), String.valueOf(progress), Toast.LENGTH_SHORT).show(); break; case MotionEvent.ACTION_CANCEL: break; } return true; } } MainActvity.java package com.example.imagerotation; import android.app.Activity; import android.os.Bundle; import android.view.Menu; import android.view.MenuItem; import android.widget.TextView; public class MainActivity extends Activity { private VerticalSeekBar seek; private TextView by; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); seek = (VerticalSeekBar)findViewById(R.id.seekBar1); by = (TextView)findViewById(R.id.textView1); by.setText(String.valueOf(seek.getProgress())); } }

    Read the article

  • CastClassException on Custom View

    - by tuxGurl
    When I try to findViewById() on my custom view I keep getting a ClassCastException. I've tried so many things that I'm sure I've botched the code now! To make sure I'm not going insane I stripped down the classes to their bare minimum inorder to find what was wrong. I'm new to android programming and I'm sure I'm missing something basic. This is BaseImageView an extended view class. package com.company.product.client.android.gui.views; import android.content.Context; import android.graphics.Canvas; import android.graphics.Color; import android.view.View; public class BaseImageView extends View { public BaseImageView(Context context) { super(context); } @Override protected void onDraw(Canvas canvas) { super.onDraw(canvas); canvas.drawColor(Color.GREEN); } } This is LiveImageView an extension of the BaseImageView class. package com.company.product.client.android.gui.views; import android.content.Context; import android.util.AttributeSet; public class LiveImageView extends BaseImageView { public LiveImageView(Context context, AttributeSet attrs) { super(context); } } Here is the Layout my_view.xml. <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:orientation="vertical" android:layout_width="fill_parent" android:layout_height="fill_parent" android:gravity="center"> <View class="com.company.product.client.android.gui.views.LiveImageView" android:id="@+id/lvImage" android:layout_width="wrap_content" android:layout_height="wrap_content" /> </LinearLayout> And here is the onCreate in my Activity LiveViewActivity. @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); try { setContentView(R.layout.my_view); final LiveImageView lvImage = (LiveImageView) findViewById(R.id.lvImage); } catch (final Exception e) { Log.e(TAG, "onCreate() Exception: " + e.toString()); e.printStackTrace(); } Finally, this is stack trace. 02-11 17:25:24.829: ERROR/LiveViewActivity(1942): onCreate() Exception: java.lang.ClassCastException: android.view.View 02-11 17:25:24.839: WARN/System.err(1942): java.lang.ClassCastException: android.view.View 02-11 17:25:24.839: WARN/System.err(1942): at com.company.product.client.android.gui.screen.LiveViewActivity.onCreate(LiveViewActivity.java:26) 02-11 17:25:24.839: WARN/System.err(1942): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1047) 02-11 17:25:24.849: WARN/System.err(1942): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2459) 02-11 17:25:24.849: WARN/System.err(1942): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2512) 02-11 17:25:24.849: WARN/System.err(1942): at android.app.ActivityThread.access$2200(ActivityThread.java:119) 02-11 17:25:24.849: WARN/System.err(1942): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1863) 02-11 17:25:24.859: WARN/System.err(1942): at android.os.Handler.dispatchMessage(Handler.java:99) 02-11 17:25:24.859: WARN/System.err(1942): at android.os.Looper.loop(Looper.java:123) 02-11 17:25:24.859: WARN/System.err(1942): at android.app.ActivityThread.main(ActivityThread.java:4363) 02-11 17:25:24.869: WARN/System.err(1942): at java.lang.reflect.Method.invokeNative(Native Method) 02-11 17:25:24.869: WARN/System.err(1942): at java.lang.reflect.Method.invoke(Method.java:521) 02-11 17:25:24.869: WARN/System.err(1942): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:860) 02-11 17:25:24.869: WARN/System.err(1942): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:618) 02-11 17:25:24.879: WARN/System.err(1942): at dalvik.system.NativeStart.main(Native Method)

    Read the article

  • Android: Programatically Add UI Elements to a View

    - by Shivan Raptor
    My view is written as follow: package com.mycompany; import android.view.View; import java.util.concurrent.TimeUnit; import java.util.ArrayList; import android.content.Context; import android.graphics.Canvas; import android.graphics.Color; import android.util.AttributeSet; import android.graphics.Paint; import android.graphics.Point; import android.hardware.Sensor; import android.hardware.SensorEvent; import android.hardware.SensorEventListener; import android.hardware.SensorManager; import android.widget.*; public class GameEngineView extends View implements SensorEventListener { GameLoop gameloop; String txt_acc; float accY; ArrayList<Point> bugPath; private SensorManager sensorManager; private class GameLoop extends Thread { private volatile boolean running = true; public void run() { while (running) { try { TimeUnit.MILLISECONDS.sleep(1); postInvalidate(); pause(); } catch (InterruptedException ex) { running = false; } } } public void pause() { running = false; } public void start() { running = true; run(); } public void safeStop() { running = false; interrupt(); } } public void unload() { gameloop.safeStop(); } public GameEngineView(Context context, AttributeSet attrs, int defStyle) { super(context, attrs, defStyle); // TODO Auto-generated constructor stub init(context); } public GameEngineView(Context context, AttributeSet attrs) { super(context, attrs); // TODO Auto-generated constructor stub init(context); } public GameEngineView(Context context) { super(context); // TODO Auto-generated constructor stub init(context); } private void init(Context context) { txt_acc = ""; // Adding SENSOR sensorManager=(SensorManager)context.getSystemService(Context.SENSOR_SERVICE); // add listener. The listener will be HelloAndroid (this) class sensorManager.registerListener(this, sensorManager.getDefaultSensor(Sensor.TYPE_ACCELEROMETER), SensorManager.SENSOR_DELAY_NORMAL); // Adding UI Elements : How ? Button btn_camera = new Button(context); btn_camera.setLayoutParams(new LinearLayout.LayoutParams(LinearLayout.LayoutParams.FILL_PARENT, LinearLayout.LayoutParams.FILL_PARENT)); btn_camera.setClickable(true); btn_camera.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { System.out.println("clicked the camera."); } }); gameloop = new GameLoop(); gameloop.run(); } @Override protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) { // TODO Auto-generated method stub //super.onMeasure(widthMeasureSpec, heightMeasureSpec); System.out.println("Width " + widthMeasureSpec); setMeasuredDimension(widthMeasureSpec, heightMeasureSpec); } @Override protected void onDraw(Canvas canvas) { // TODO Auto-generated method stub // super.onDraw(canvas); Paint p = new Paint(); p.setColor(Color.WHITE); p.setStyle(Paint.Style.FILL); p.setAntiAlias(true); p.setTextSize(30); canvas.drawText("|[ " + txt_acc + " ]|", 50, 500, p); gameloop.start(); } public void onAccuracyChanged(Sensor sensor,int accuracy){ } public void onSensorChanged(SensorEvent event){ if(event.sensor.getType()==Sensor.TYPE_ACCELEROMETER){ //float x=event.values[0]; accY =event.values[1]; //float z=event.values[2]; txt_acc = "" + accY; } } } I would like to add a Button to the scene, but I don't know how to. Can anybody give me some lights? UPDATE: Here is my Activity : public class MyActivity extends Activity { private GameEngineView gameEngine; @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); // add Game Engine gameEngine = new GameEngineView(this); setContentView(gameEngine); gameEngine.requestFocus(); } }

    Read the article

  • Photo inside the image view should not go cross on dragging

    - by TGMCians
    I want photo inside the imageview should not go outside on dragging. In my code when i start to drag bitmap inside the imageview its goes out from imageview but i want when it cross the imageview its should come at starting point of imageview. How to achieve this. please help me for this. @Override protected void onDraw(Canvas canvas) { super.onDraw(canvas); canvas.save(); scaleCount=scaleCount+scale; angleCount = addAngle(angleCount, Math.toDegrees(angle)); Log.v("Positions", "X: "+x+" " + "Y: "+y); Log.d("ScaleCount", String.valueOf(scaleCount)); Log.d("Angle", String.valueOf(angleCount)); if (!isInitialized) { int w = getWidth(); int h = getHeight(); position.set(w / 2, h / 2); isInitialized = true; } Paint paint = new Paint(); Log.v("Height and Width", "Height: "+ getHeight() + "Width: "+ getWidth()); transform.reset(); transform.postTranslate(-width / 2.0f, -height / 2.0f); transform.postRotate((float) Math.toDegrees(angle)); transform.postScale(scale, scale); transform.postTranslate(position.getX(), position.getY()); canvas.drawBitmap(bitmap, transform, paint); canvas.restore(); BitmapWidth=BitmapWidth+bitmap.getScaledWidth(canvas); BitmapHeight=BitmapHeight+bitmap.getScaledHeight(canvas); try { /*paint.setColor(0xFF007F00); canvas.drawCircle(vca.getX(), vca.getY(), 30, paint); paint.setColor(0xFF7F0000); canvas.drawCircle(vcb.getX(), vcb.getY(), 30, paint);*/ /*paint.setColor(0xFFFF0000); canvas.drawLine(vpa.getX(), vpa.getY(), vpb.getX(), vpb.getY(), paint); paint.setColor(0xFF00FF00); canvas.drawLine(vca.getX(), vca.getY(), vcb.getX(), vcb.getY(), paint);*/ } catch(NullPointerException e) { // Just being lazy here... } } @Override public boolean onTouch(View v, MotionEvent event) { vca = null; vcb = null; vpa = null; vpb = null; x=event.getX(); y=event.getY(); try { touchManager.update(event); if (touchManager.getPressCount() == 1) { vca = touchManager.getPoint(0); vpa = touchManager.getPreviousPoint(0); position.add(touchManager.moveDelta(0)); } else { if (touchManager.getPressCount() == 2) { vca = touchManager.getPoint(0); vpa = touchManager.getPreviousPoint(0); vcb = touchManager.getPoint(1); vpb = touchManager.getPreviousPoint(1); VMVector2D current = touchManager.getVector(0, 1); VMVector2D previous = touchManager.getPreviousVector(0, 1); float currentDistance = current.getLength(); float previousDistance = previous.getLength(); if (currentDistance-previousDistance != 0) { scale *= currentDistance / previousDistance; } angle -= VMVector2D.getSignedAngleBetween(current, previous); /*angleCount=angleCount+angle;*/ } } invalidate(); } catch(Exception exception) { // Log.d("VM", exception.getMessage()); } return true; }

    Read the article

  • Mixing XNA and silverlight gives wierd graphics

    - by Mech0z
    I making a small 3dgame which is made as a Silverlight and XNA app, but when I draw the sprites the graphics becomes all wierd. All my primitive types are rendered correctly, but my 3d models are just wierd My Draw is like this when silverlight is set to draw private void OnDraw(object sender, GameTimerEventArgs e) { // Render the Silverlight controls using the UIElementRenderer elementRenderer.Render(); // Clear the screen to a solid color SharedGraphicsDeviceManager.Current.GraphicsDevice.Clear(Color.CornflowerBlue); switch (gameState) { case GameState.ChooseStarter: TextBlockStatus.Text = "Find Starting Player"; break; case GameState.PlaceBrick: TextBlockPlayer.Text = (playerTurn == PlayerTurn.PlayerOne) ? "Player One" : "Player Two"; TextBlockState.Text = "Place Brick"; foreach (IGraphicObject obj in _3dObjects) { obj.Draw(cameraPosition, e); } break; case GameState.GiveBrick: TextBlockState.Text = "Give Brick"; break; } spriteBatch.Begin(); // Using the texture from the UIElementRenderer, // draw the Silverlight controls to the screen spriteBatch.Draw(elementRenderer.Texture, cameraProjection, Color.White); spriteBatch.End(); } This gives me this output If I comment the spritebatch lines out I get the correct output, except the silverlight text is of course not shown I am not entirely sure what to look for except that zero vector I am giving to the spritebatch, but if thats the source I have no idea what I am supposed to set it as epspecially when its a 2d vector

    Read the article

< Previous Page | 1 2 3 4 5  | Next Page >