Android :: Drawing Text In Custom View Using Canvas.drawtext
Jul 19, 2010
I am drawing text in my custom view in android using canvas.drawtext. i need to change back color, and want text right aligned. for example i want to print the text in a 10, 10, 100, 20 rectangle of color yellow and text color red and right aligned. how can i do that ?
View 2 Replies
Sep 9, 2010
I am using SurfaceView to draw my game on the screen of the phone. Basically now I want to be able to draw Android Views on my View, such as a Button or ListView. I am simlpy getting a Canvas and then I draw on that... does anybody know how to draw AndroidViews (Button, ListView.) on my Canvas?
View 2 Replies
View Related
Apr 16, 2010
I have a view, I'm drawing with the Canvas object in the onDraw(Canvas canvas) method.
My code is:
CODE:....................
The problem is the text doesn't show through the background, what am I doing wrong? If I remove the canvas.drawPaint(paint) and paint.setColor(android.R.color.black) you can see the text on the screen.....
View 2 Replies
View Related
Jan 16, 2010
I believe I know the basics and have successfully published a nice graphical game (Tairu). I know about inflating an xml layout and instantiating views that work.
For my current project, I really just want something similar to the Windows 'DrawText' function where it will draw a bit of a text inside an arbitrary rectangle of the surface, and do word wrap within that rectangles boundaries. That's what I really WANT, but I can't find any form of drawText that will wrap.
So, while that's what I WANT, I can accept the thought of programmatically instantiating a TextView (which wraps beautifully). But I still need to be able to provide the rectangle, which is highly dynamic. (which is why I want to call a form of drawText inside of my onDraw method). In this particular case, I have something which is static to a particular view instance (I mean, the View becomes visible, the position is set, and does not change after that. but the text position is dependent on game state and cannot be pre-determined inside an XML layout). So in this one case, I could afford the expense of runtime recalculation of the layout when the view is displayed.
OK, fine. So I do something like this:
CODE:......
Pretend you didn't see 'AbsoluteLayout' there, I am desperate and have tried all possible layout classes
main_frame is defined in my main XML layout (it is the outermost layout, fills the parent, and, as I said, I've tried all the offered layouts)
With this code, the textView appears, but along the top of the layout, and not using the width I provided either.
Adding, out of desperation.
CODE:.......
makes no difference. In fact, so far, NOTHING has made any difference. So I thought, ok, while this seems like a useful thing to be able to do, I can accept if it can't. I accept that it is impossible to provide dimensions in advance and that you have to override the measure and layout callbacks then requestLayout and in your overrides, force the final layout for the TextView.
Of course, that is completely unacceptable for my FIRST desire (a drawText that wraps to a rectangle, called from onDraw as needed). But the point is I feel something like that OUGHT to work, and it doesn't, so clearly this is MY fault.
Getting back to what I WANT, I guess I can do it myself by repeated calls to measure text and parsing the string for spaces until I get the N characters which fit on the first line, then repeat for additional lines, calling a normal drawText for each line (and using textMetrics to determine the vertical offset to the next line.)
But why wouldn't that method already exist? I promise not to fill the screen with a zillion calls, and/or to cache pre-rendered text on some bitmap somewhere if antialiased drawText is too expensive to repeat frequently.
View 7 Replies
View Related
Jun 30, 2010
I tried to write some text on a surface view I created. It works fine, if title is false, and there is no linebreak added to the text. But if I add a title and therefore a linebreak, the linebreak isn't printed as expected, but instead there is this symbol [] printed.
CODE:...................
View 1 Replies
View Related
Jan 7, 2010
I have one lengthy string & I need to draw that on the device display.
My code is as follows:
CODE:...................
But the problem here is, the string is going out of the screen. I want it to break down into multiple lines if it is too big for the screen width. Is there any other better way than using canvas class?
View 2 Replies
View Related
Jul 6, 2010
I have a few doubts about view flipper I am using viewflipper to go to another view using scroll_left animation. i have kept 2 linearlayouts inside the ViewFlipper Code...
View 2 Replies
View Related
Sep 26, 2010
I'm trying to draw a custom border by drawing a custom view. Here is a sample of one side of the border: Code...
View 1 Replies
View Related
Aug 2, 2009
I got this code from another post and modified it to work for me as a TextView. I tried using the code below but no transformation is happening? I trying to draw the canvas of the TextView with the given Matrix transformation.
import android.content.Context; import android.graphics.Canvas; import android.graphics.Matrix; import android.util.AttributeSet; import android.view.MotionEvent; import android.widget.TextView;
public class CTextView extends TextView { private Matrix mForward = new Matrix(); private Matrix mReverse = new Matrix(); private float[] mTemp = new float[2];
public CTextView(Context context) { super(context); mForward.postRotate(90); mForward.invert(mReverse); } public CTextView(Context context, AttributeSet attrs) { super(context, attrs);
mForward.postRotate(90); mForward.invert(mReverse); } public CTextView(Context context, AttributeSet attrs, int defStyle) { super(context, attrs, defStyle);
mForward.postRotate(90); mForward.invert(mReverse); }
@Override protected void dispatchDraw(Canvas canvas) { canvas.save(); canvas.concat(mForward); canvas.restore(); super.dispatchDraw(canvas); }
@Override public boolean dispatchTouchEvent(MotionEvent event) { final float[] temp = mTemp; temp[0] = event.getX(); temp[1] = event.getY();
mReverse.mapPoints(temp); event.setLocation(temp[0], temp[1]); return super.dispatchTouchEvent(event); }
View 3 Replies
View Related
Nov 4, 2010
I have two bitmap overlapped .The top bitmap is transparent and when user touch to screen i copy pixels from another bitmap to top bitmap.My goal is to give to users the feeling of erasing image with touching to see another image.However it is not working properly especially when user drags his finger too fast on the screen.I made a few tests and i beleive drawing bitmaps to the canvas every time cause the lag but i don't know how to fix it.
View 1 Replies
View Related
Sep 10, 2009
I am facing a problem. I launched a webview with some url. After url is completely loaded I try to get its content in a Canvas. But I am unable to do so. its crashing at libsgl.so
My goal is to get webview complete data in a bitmap. There is one api getDrawingCache() which gets the webview data in a bitmap format, but it gets only the visible content. I actually want the whole content in a bitmap.
If there is some another way, then how can I go about that.
Here is mine code....
View 2 Replies
View Related
Nov 3, 2010
I am on Android 2.1 and I have one multi column Custom listview Using BaseAdapter with an editable edittext at the end of the listview. If the data in the listview do not contain the data of user choice then user should be able to enter data. If the data is already there in the list user will be able to select the data using custom selector. If a selection is made in the list view and user wanted to enter data in the text field at the bottom after selection then the marker in the list view should be unselected. I tried to use onclick() method on edit text using click listener. First time when it is clicked, edit text is getting focus and onclick() method is not fired. And when it is clicked second time, onclick() method is fired and notifyDataSetChanged() method is called. I tried to call the notifyDataSetChanged() method from the Focus Listener, list view selection is gone in my first attempt and edit text is not receiving any data input from the keyboard (frozen).
View 1 Replies
View Related
Jan 27, 2010
I'm dealing with a phone that has no physical keyboard and I'm using my own custom view for rendering. The device I'm working with, by default, seems to be in a T9 type entry mode where it suggests blocks of text. However, it never sends me the actual key events.
How do I tell whatever soft-keyboard that pops up to enter 'dumb' key event sending mode?
The InputMethodManager has a "isAcceptinText()" call which would tell me if it's in event-sending mode, but not a method to set it. Digging through the documentation hasn't produced any insight. How do I tell the input manager that I only want key events?
View 1 Replies
View Related
Oct 8, 2010
I want to display List of Contact Names with the respective phone numbers like
Vikas Patidar <9999999999>
Rahul Patidar <9999999999>
Using AutoCompleteTextView when a user type text in the mobile number field. In default style I can only display the list of names. Can anyone please tell me how can I implement this so that when a user select any item in list and I can display number of that in Mobile number field.
View 3 Replies
View Related
May 26, 2010
I'm having a small problem with drawing a View offscreen to a Bitmap. The View is created using LayoutInflater.inflate(int resource, ViewGroup root) with null passed to the root parameter. The View has a fixed size (200x180 pixels). I can create a Bitmap for this View either by using the method View.getDrawingCache() or by calling View.draw(Canvas canvas) using a Canvas that in turn has a backing Bitmap. This works fine if the View doesn't change after the inflate. However, if I have a TextView inside my View that I will update, the size of the TextView is never updated regardless of what method I call on the View (requestLayout(), forceLayout() invalidate() etc.). If I display the View on screen directly, everything works fine (sizes are updated as needed, etc.). What is the correct way of drawing Views off screen and being able to update their layout when needed?
View 3 Replies
View Related
Mar 31, 2009
I'm trying to create a custom widget which looks lick HTML table. I chose to derive from TableLayout, which is the subclass of ViewGroup and View. What's confusing me is that the drawing I put into my override of View.onDraw did not take effect, until I moved the codes to the override of ViewGroup.dispatchDraw. I know dispatchDraw is a good place to draw something, but I'm just wondering why there's such difference in my practice?
View 3 Replies
View Related
Aug 10, 2010
I created a custom OverlayItem class so that I could essentially have one kind of OverlayItem whose Drawable marker would set itself depending on the state of some data that I pass into it. I have attempted to accomplish this by, on my first attempt, utilizing the setMarker method within the OverlayItem class. Once that did not work I attempt to override the getMarker method and have it return the appropriate marker to represent the data. Both of these attempts ended with nothing being drawn on the map...however if they are commented out the markers draw just fine (except they of course use the default marker, which isn't what I want). Here is my code for my custom OverlayItem class (the commented out methods I have tried and they have not worked):
private class MyOverlayItem extends OverlayItem {
private Context mContext; private MyData mData;
public MyOverlayItem(GeoPoint point, MyData data, Context context) {
super(point, data.getWhat(), data.getWhere()); this.mContext = context; this.mData = data;
/*if(data.getTemp() > 200) this.setMarker(res.getDrawable(R.drawable.icon_data_hot_l));
else if(data.getTemp() > 100) this.setMarker(res.getDrawable(R.drawable.icon_data_neutral_l));
else this.setMarker(res.getDrawable(R.drawable.icon_data_frozen_l));*/ }
/*@Override public Drawable getMarker(int stateBitset) {
Resources res = this.mContext.getResources(); if(this.mData.getTemp() > 200)
return res.getDrawable(R.drawable.icon_data_hot_l); else if(this.mData.getTemp() > 100)
return res.getDrawable(R.drawable.icon_data_neutral_l);
return res.getDrawable(R.drawable.icon_data_frozen_l);
}*/ }
Is there a way to do what I am attempting to do or do I need to make a unique OverlayItem class corresponding to each state of my data?
View 3 Replies
View Related
Jun 23, 2009
I would like to draw custom images within a ListView, for this I have created a ListView and an ArrayAdapter object. I have specified that each element of the ListView will be an ImageView which is specified by an XML layout file. Now, I would like to draw a custom graphic in each cell depending upon certain paramters.
View 3 Replies
View Related
Jul 13, 2010
I am trying to put a background image and draw on top of that screen. I assumed activity will have a on draw method, but it does not have. it seems i need to use surfaceview. Can I put a surfaceview on top of the image view and make it transparent ? any example/tutorial i can refer to ?
View 5 Replies
View Related
May 4, 2009
Can you please tell me how does android determine when View should enable the drawing cache? I try calling in my class (which inherits form LinearLayout) Bitmap drawingCache = getDrawingCache(); I get a null in my drawingCache.
View 5 Replies
View Related
Aug 30, 2010
I'm trying to create the simplest 2D drawing program possible to isolate what exactly I can't figure out about drawing. This program should literally just draw a 20x20 rectangle. Here's what I have: Code...
View 1 Replies
View Related
Jul 6, 2009
I have made a custom widget, very similar to JTable in Swing. It is not editable, and all data is replaced at once, allowing easy checking for the widest item in each column & custom col sizing at replace time. It is a subclass of LinearLayout, filled with re-usable TableRow Objects, sub-classed directly from View.
TableRow is both Clickable, focusable, & focusable In Touch Mode. TableRow overrides onDraw(Canvas), calling super. It draws the first column in Black with Lt gray underneath. If the TableRow isFocused () , then a filled rectangle is drawn, before the rest of the cols (left or right justified based on data type), and borders. Where do I get the color, orange, to draw the filled rectangle indicating focus? android.R.drawable.list_selector_background seems to be a pointer, value 17301602, not an actual color. Placing any real Color in my code draws things fine. Is this 17301602 transparent or something? Am I doing this wrong, or do I just need to know how to fine the orange?
View 2 Replies
View Related
Feb 9, 2010
I have a linear layout that I have overridden because I want to > dynamically add other views to it. I am trying to add some textviews > to it and I call addViewToLayout in the onLayout method. Can't you just add your views to the layout using addView()? I have one custom LinearLayout and this is what I do and it works fine. No need to override onLayout() or onDraw(). Maybe try that
View 10 Replies
View Related
Apr 8, 2010
I am working on something that needed custom drag-and-drop functionality, so I have been subclassing View, doing a bunch of math in response to touch events, and then rendering everything manually through code on the canvas in onDraw. Now, the more functionality I add, the more the code is growing out of control and I find myself writing a ton more code than I would expect to write in a high level environment like Android.
Is this how it's done, or am I missing something? If I'm not doing anything fancy in the UI, the framework handles the majority of my interactions. Built-in controls handle the touches and drags, and my code is pretty much limited to business logic and data. Is there a way to leverage the power of some of the UI controls and things like animations while also doing some of it manually in the onDraw canvas? Is there an accepted standard of when to use one or the other (if indeed the two approaches can be mixed)?
View 2 Replies
View Related
May 12, 2010
I'm working with Android 2.1 and have the following problem:
Using the method View.getDrawingCache() always returns null. getDrawingCache() should return a Bitmap, which is the presentation of View's content.
Example code:
public void onCreate(final Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
final View view = findViewById(R.id.ImageView01);
view.setDrawingCacheEnabled(true);
view.buildDrawingCache();
final Bitmap bmp = view.getDrawingCache();
System.out.println(bmp);
}
I've already tried different ways to configure the View object for generating the drawing cache (e.g. View.setWillNotDraw(boolean) and View.setWillNotCacheDrawing(boolean)), but nothing works. What is the right way, or what I'm doing wrong? In real code I want to apply getDrawingCache() on a ViewGroup like RelativeLayout. Is the behaviour the same when using a ViewGroup?
View 2 Replies
View Related
Aug 26, 2009
I have a View and that has a canvas. I am rotating the canvas, for rotating a bitmap. But after that, I need to draw one more bitmap on the Canvas and, this should not rotate. The second bitmap has to be static.
I tried with matrix rotation for bitmap. But its not rotating in the specified co-ordinates.
View 3 Replies
View Related
Apr 5, 2010
I'm trying to build a custom clock view in Android. See image http://twitpic.com/1devk7.So far to draw the time and hour markers I have been using the Canvas.rotate method to get the desired effect. However, notice that it is difficult to interpret the numbers in the lower half of the clock (e.g. 6 or 9?) because of the angle in which they are drawn.When using drawText, is it possible to draw the text at 45/90/180 degrees so that all text appears upright when my onDraw method has finished?
View 1 Replies
View Related
Mar 11, 2010
I am trying to draw an animation. To do so I have extended View and overridden the onDraw() method. What I would expect is that each time onDraw() is called the canvas would be in the state that I left it in and I could choose to clear it or just draw over parts of it (This is how it worked when I used a SurfaceView) but each time the canvas comes back already cleared. Is there a way that I can not have it cleared? Or maybe save the previous state into a Bitmap so I can just draw that Bitmap and then draw over top of it?
View 4 Replies
View Related
Mar 6, 2009
Can anyone explain me the difference between View's Canvas and Bitmaps Canvas
View 2 Replies
View Related
Sep 29, 2010
I have a view that is round and hovering above (-> in z-axis direction coming out of the screen) the main content. When the someone taps the screen I want either the main content to be selected or the view hovering above, when it covers the main view.
So far that works perfectly. I have a round shaped item on a transparent canvas. Meaning you can see everything of the background that is outside of that circle. However, you cannot select it, because it is still the hovering canvas, just with a transparent paint.
Now I'm wondering, to solve this issue, if it is possible to make the view/canvas itself round shaped?
Update
I added an image for better explanation what I try to achieve.
View 2 Replies
View Related