Android :: Drawing Word-wrapped Text At Arbitrary Position On A Canvas

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.

Android :: drawing word-wrapped text at arbitrary position on a canvas


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 View Related

Android :: Button In Arbitrary Position Over RelativeLayout

Apr 28, 2010

I'm trying to build an android application that features a graphical display drawn within a RelativeLayout. I want to place "+" and "-" buttons next to several of the parameters, which are drawn at various points on the canvas. The positions are free-form don't seem to conform to any of the standard XML layouts.I know how to create the buttons programmatically, but I don't know how to place them over the canvas where I need them to be. I'm assuming that this would be done in the view thread's doDraw() method, after all the graphics have been drawn, but how?

View 2 Replies View Related

Android :: Drawing Canvas With Given Matrix Transformation?

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

Android :: Drawing View On My Own SurfaceView / Canvas

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

Android :: App Gets Too Slow While Drawing Two Bitmaps On A Canvas / Fix It?

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

Android :: Droid TextView Text Not Getting Wrapped / Why Is So?

Feb 4, 2010

Can any one tell me whats going wrong with the text, text exceeds then one line not getting wrap to next line going beyond the screen.

Following is the code...

View 5 Replies View Related

Android :: Crash At Drawing WebView Into Canvas / Solve This?

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

Android :: Android: Place A Button At An X,y Position Over Top Of Canvas

Apr 16, 2010

Is it possible to place buttons at an X,Y position over the top of a Canvas?

For example, on the opening screen of my game, I would like to place buttons for "Play Now", "Instructions", etc, right on top of the canvas.

Right now, I'm looking at Touch locations on the Canvas and comparing them to various X,Y bounds. It works, but adding a button with a click listener would probably be much more efficient.

View 1 Replies View Related

Android :: Drawing Text Upside Down

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

Sony Ericsson Xperia X10 :: 1.6 Text Msg's Would Predict Your Next Word - Based On Last Time You Sent A Similar Text

Nov 30, 2010

But now I'm on 2.1, it doesn't do anything of the sort.

e.g. let's say i had sent out a text stating; "Hi John, I will be at yours next week - you can email me at berty@bassett.com if you need me to bring anything"

so a few days later I'd start a new text. By the time I'd wrote "Hi" the system would offer me the next word as "John" - it had kind of learned what it thought I might want to say next. This was incredibly useful when entering email addresses into form pages.

Now, when I type "Hi", it offers stupid suggestions like "Hit, High, Hill" and other completely unrelated junk.

If I enable predictive texts, it auto fixes words that don't need auto fixing. I sent a text to my sister saying "lolzalot" and by the time I realised what had gone on, it had instead replaced my word with "locally"

Why is this new way of doing things so poor compared to the old 1.6 way? Or at least, how can I get it back to being like it should be.

View 2 Replies View Related

Android :: Extend TextView To Allow Drawing Of Text With A Gradient Effect?

Apr 21, 2010

How would I extend TextView to allow the drawing of text with a gradient effect?

View 2 Replies View Related

Android :: Draw Text On Canvas?

Oct 28, 2010

i'm trying to develop a simple pie chart class for android. For now, it can take a map of labels and values and draw the pie chart. I'm yet to add the legends for the pie, which is where i need to place the texts near small rectangles on the screen corner. Any help appreciated, since i'm new to Android dev.

View 1 Replies View Related

Android :: Using StaticLayout With Canvas To Draw Text

Feb 4, 2010

I have figured out the static layout this far, but I have no idea how to make it display my text anywhere else but in the top left corner. StaticLayout layout = new StaticLayout(text, getTextPaint(), 140, android.text.Layout.Alignment.ALIGN_CENTER,(float)1.0, (float)0.0, true); layout.draw(canvas);

View 2 Replies View Related

Android :: Not Getting Complete Text While Animation On Canvas

Nov 16, 2010

I want to get an animated text in Android where it should run from left to right on the screen.

Eg: I want to get this text. private static final String QUOTE = "Nobody uses Java anymore. It's this big heavyweight ball and chain.";

running from right to left using animation.

However, this text gets truncated to "Nobody uses Java anymore. It's" in Portrait mode and to "Nobody uses Java anymore. It's this big heavyweight" in landscape mode.

This is the code that I have used:

CODE:......................

View 1 Replies View Related

Android :: How To Copy Text From Web And Save As Word DOC To SD Card?

Jan 9, 2010

Anyways I was wondering how or what app would allow me to copy text from a webpage and then save it to sd card?

View 3 Replies View Related

Android :: Measuring Text Width To Be Drawn On Canvas

Jul 15, 2010

Is there a method which returns the width ( in pixels ) of a text to be drawn on an Android canvas using the drawText() method according to the Paint used to draw it.

View 1 Replies View Related

Android :: Measuring Text Height To Be Drawn On Canvas

Sep 6, 2010

Any straight forward way to measure the height of text? The way I am doing it now is by using Paint's measureText() to get the width, then by trial and error finding a value to get an approximate height. I've also been messing around with FontMetrics, but all these seem like approximate methods that suck. I am trying to scale things for different resolutions. I can do it, but I end up with incredibly verbose code with lots of calculations to determine relative sizes. I hate it! There has to be a better way.

View 1 Replies View Related

Android :: Cursor Position At The End Of Text

Aug 26, 2009

When i try to edit and already stored notepad ,i see the cursor at the end of first line.I want to make it appear to the end of the text.Please help me in this.

View 2 Replies View Related

Android :: How To Set Position Of Indicator Text?

Jan 31, 2010

i'm trying to use TabHost and TabWidget in my Android application.The problem is that i do not want my tabs to be so tall (65px). However, if i set the layout_height of the TabWidget to e.g. 30px, i can't see the tab labels (indicator) on the tabs at all.Seems like there is a "minimum required" height for the TabWidget (65px?) and the indicator is positioned at the bottom of this 65px?Is there a way to adjust the positioning of the indicator?

View 4 Replies View Related

Android :: EditText Wrapped In ScrollView

Jul 21, 2010

I have an issue with EditText when it's wrapped in ScrollView.

Please see the following layout setup:

CODE:............

There's nothing special about this layout. I just want the EditText inside ScrollView to be scrollable when I entered more than 5 lines of text.

I tested this layout with both Eclair and Froyo and Eclair seemed working fine, but Froyo didn't really work at all. Was there any change on ScrollView?

ScrollView api says that I can put EditText(or TextView) inside of ScrollView to have this kind of functionality, so I guess that I did make a mistake or missed something important.

View 3 Replies View Related

Android :: How To AlignParentBottom When Wrapped In ScrollView?

Jun 27, 2010

The problem I am having seems to be that if I have a view (e.g. myButton) inside a RelativeLayout set to alignParentBottom - (as per the code below) - and then wrap the RelativeLayout with a scrollview (necessary so the content will be viewable on smaller screens or when orientation changes to landscape) - then, when the parent bottom is NOT visible (for example when changed to landscape orientation) myButton is displayed at the TOP of the page - NOT the bottom.How can you align a view to the bottom of the screen and have it remain at the bottom even if the bottom is below the scroll?

View 1 Replies View Related

Android :: How To Write Centered Multi Colored Text To Canvas

Sep 10, 2010

I am writing to a canvas from a thread.

public void draw(Canvas canvas) {
Paint p = new Paint();
p.setAntiAlias(true);
p.setTextSize(30);
p.setColor(Color.WHITE);
p.setTextAlign(Paint.Align.CENTER);
canvas.drawText("Centered", xCentre, yCentre, p);
}

My problem start when I have a multi colored SpannableStringBuilder which I want to write to the canvas, and I have no idea how to do this. SpannableStringBuilder has a drawText() method which I have been unable to use. Or is there some other method to write a string to a canvas where some of the letters have a different color?

View 1 Replies View Related

Android :: Position A Text Of A RadioButton At The Bottom

Dec 6, 2009

Is There any way to possition a text of a RadioButton at the bottom, centered in the middle, short of writing my own custom buttom?

View 3 Replies View Related

Android :: Rich Text/Word Processor With Edit Mode As Default

Jul 25, 2010

While it is possible to edit text or type in Docs to Go and QuickOffice, to get to the edit mode is a PITA. The default in Docs to Go is Zoom in or out? WTF. You have to got to menu and toggle the keyboard to be able to add or edit text.

Is there a good notepad or word processing program that defaults to keyboard input? Better yet is there one that also allows highlighting text to cut, copy or paste?

View 2 Replies View Related

Android :: Insert Text Into EditText At Current Position?

Aug 31, 2010

I want to insert a constant string into an EditText by the press of a button. The string should be inserted at the current position in the EditText.
If I use EditText.append the text gets inserted at the end of the EditText.

How can I do that? I couldn't find a suitable method.

View 3 Replies View Related

Android :: Custom Position Of Hint In Edit Text Box.

Jul 5, 2010

If there was any way that I could get a hint at the bottom of an Edit Text view -- and then the user to start entering text at the top of the box.

As a bonus question, is there any way I can make the hint NOT disappear once the user starts entering text.

View 1 Replies View Related

Android :: Setup Text Position Programmatically In EditText Class?

May 28, 2010

Does smomeone know how I set the scrollbar position in an EditView programmatically.

I'm appending the text during special events but I want the EditView to scroll down to the latest text added so it'll be visible. But default the scrollbar does not move automatically when appending text.

View 1 Replies View Related

Android :: Reset Canvas - Draw A New Bitmap Into The Canvas

Jul 7, 2010

My loadMap() method generate a canvas.throwIfRecycled exception when i try to load a new map.
When i start the game, the initial map loads and work fine though,
its only when i try to load a new map that i get the exception ..

How can i "reset" canvas and the bitmap i use to draw into, so i can startover fresh with them ?
here's what i use to create and draw my maps:

CODE:.........

So basicaly once i created and used picDest and canvas, i cannot figure how to reset it all for when i want to load a new map..

View 1 Replies View Related

Android :: Get Original Index / Position Of Item Instead Of One Showing In Filtered Text

Mar 26, 2010

I am creating a list .. the elements of the list are drawn from sqlite database .. I populate the list using ArrayList and ArrayAdapter ...upon clicking the items on the list I want to be able to fire an intent containing info about the item clicked ... info like the index number of the item .. using the method : onItemClick(AdapterView av, View v, int index, long arg)

I do get index of the item clicked . however it is of the list currently displayed . the problem comes when I do setFilterTextEnabled(true) , and on the app type in some text to to search some item ..and then click it ..rather than giving me the index of the item on the original list it gives me the index on filtered list..

following is the snippet of code:
myListView.setOnItemClickListener(new OnItemClickListener() {
public void onItemClick(AdapterView<?> av, View v, int index, long arg) {
Intent lyricsViewIntent = new Intent(iginga.this, LyricsPage.class);
lyricsViewIntent.putExtra("title", songList.get((int)arg).getTitle());
lyricsViewIntent.putExtra("id", songList.get((int)arg).getSongId());
startActivity(lyricsViewIntent);
}
});
myListView.setTextFilterEnabled(true);

Is there any way I can get the original index /position of the item instead of the one showing in filtered text ...when filtered.

View 1 Replies View Related







Copyrights 2005-15 www.BigResource.com, All rights reserved