Re: [android-developers] Re: [Help] how to draw multiple lines in Edittext?
On Mon, May 10, 2010 at 9:59 PM, social hub wrote: > What exactly is your problem here . getting line count 18 when u filled > textbox with 18 lines? > > not a problem but a tricky solution. y, in this solution , i fill 18 empty lines so getLinecount will return me 18 > On Sat, May 8, 2010 at 12:53 AM, Vincent Tsao wrote: > >> @Soical Hub: thanks for your help, your suggestion inspired me a lot >> >> i finally find this way to get padding: *getCompoundPaddingTop()*, and it >> works fine now >> >> what' more, i find another "tricky" way to meet my requirement: >> >> *Step 1: fill in the EditText with 18 'empty' line rows* >> >> StringBuilder sb = new StringBuilder(); >> for (int i = 0; i < 18; i++) { >> sb.append("\n"); >> } >> >> * this.setText(sb.toString());* >> >> >> *Step 2: draw those 18 lines >> >> * >> * * @Override >> >> protected void onDraw(Canvas canvas) { >> canvas.drawColor(paperColor); >> * int count = getLineCount(); // that's the tricky part, now >> count will return 18* >> Rect r = mRect; >> >> for (int i = 0; i < count; i++) { >> int baseline = getLineBounds(i, r); >> >> // Draw ruled lines >> canvas.drawLine(r.left, baseline + 1, r.right, baseline + 1, >> >> linePaint); >> >> canvas.save(); >> } >> super.onDraw(canvas); >> canvas.restore();** >> * *} >> >> but i don't like this tricky way personally :) >> >> >> -- >> You received this message because you are subscribed to the Google >> Groups "Android Developers" group. >> To post to this group, send email to android-developers@googlegroups.com >> To unsubscribe from this group, send email to >> android-developers+unsubscr...@googlegroups.com >> 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 android-developers@googlegroups.com > To unsubscribe from this group, send email to > android-developers+unsubscr...@googlegroups.com > 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 android-developers@googlegroups.com To unsubscribe from this group, send email to android-developers+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/android-developers?hl=en
Re: [android-developers] Re: [Help] how to draw multiple lines in Edittext?
What exactly is your problem here . getting line count 18 when u filled textbox with 18 lines? On Sat, May 8, 2010 at 12:53 AM, Vincent Tsao wrote: > @Soical Hub: thanks for your help, your suggestion inspired me a lot > > i finally find this way to get padding: *getCompoundPaddingTop()*, and it > works fine now > > what' more, i find another "tricky" way to meet my requirement: > > *Step 1: fill in the EditText with 18 'empty' line rows* > > StringBuilder sb = new StringBuilder(); > for (int i = 0; i < 18; i++) { > sb.append("\n"); > } > > * this.setText(sb.toString());* > > > *Step 2: draw those 18 lines > > * > * * @Override > > protected void onDraw(Canvas canvas) { > canvas.drawColor(paperColor); > * int count = getLineCount(); // that's the tricky part, now count > will return 18* > Rect r = mRect; > > for (int i = 0; i < count; i++) { > int baseline = getLineBounds(i, r); > > // Draw ruled lines > canvas.drawLine(r.left, baseline + 1, r.right, baseline + 1, > > linePaint); > > canvas.save(); > } > super.onDraw(canvas); > canvas.restore();** > * *} > > but i don't like this tricky way personally :) > > > -- > You received this message because you are subscribed to the Google > Groups "Android Developers" group. > To post to this group, send email to android-developers@googlegroups.com > To unsubscribe from this group, send email to > android-developers+unsubscr...@googlegroups.com > 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 android-developers@googlegroups.com To unsubscribe from this group, send email to android-developers+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/android-developers?hl=en
Re: [android-developers] Re: [Help] how to draw multiple lines in Edittext?
@Soical Hub: thanks for your help, your suggestion inspired me a lot i finally find this way to get padding: *getCompoundPaddingTop()*, and it works fine now what' more, i find another "tricky" way to meet my requirement: *Step 1: fill in the EditText with 18 'empty' line rows* StringBuilder sb = new StringBuilder(); for (int i = 0; i < 18; i++) { sb.append("\n"); } * this.setText(sb.toString());* *Step 2: draw those 18 lines * * * @Override protected void onDraw(Canvas canvas) { canvas.drawColor(paperColor); * int count = getLineCount(); // that's the tricky part, now count will return 18* Rect r = mRect; for (int i = 0; i < count; i++) { int baseline = getLineBounds(i, r); // Draw ruled lines canvas.drawLine(r.left, baseline + 1, r.right, baseline + 1, linePaint); canvas.save(); } super.onDraw(canvas); canvas.restore();** * *} but i don't like this tricky way personally :) -- You received this message because you are subscribed to the Google Groups "Android Developers" group. To post to this group, send email to android-developers@googlegroups.com To unsubscribe from this group, send email to android-developers+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/android-developers?hl=en
Re: [android-developers] Re: [Help] how to draw multiple lines in Edittext?
u can try getTop getPaddingTop as well Margins getLayoutParams and from there getting margins leftmargin you can google to find more info. With those info you can properly identify what the initial adjustment will be it can be like start from paddingtop hope it helps On Fri, May 7, 2010 at 9:36 AM, Vincent Tsao wrote: > It remind me of considering some margin space, so i change my code as > below: > > protected void onDraw(Canvas canvas) { > canvas.drawColor(paperColor); > > int count = getLineCount(); > int height = this.getMeasuredHeight(); > int line_height = this.getLineHeight(); > int page_size = height / line_height + 1; > > if (count < page_size) { > count = page_size; > } > >* int posY = 5; // i guess the margin-top may be 5 px :)* > > for (int i = 1; i < count; i++) { > *posY += line_height;* > > > canvas.drawLine(0, posY, getRight(), posY, linePaint); > canvas.save(); > > } > > super.onDraw(canvas); > canvas.restore(); > } > > finally it looks right, so i'm sure there is a margin space between my > EditText and the default view , but i have no idea about how to get this > height? so i hard code it 5 px > > any suggestion? > > -- > You received this message because you are subscribed to the Google > Groups "Android Developers" group. > To post to this group, send email to android-developers@googlegroups.com > To unsubscribe from this group, send email to > android-developers+unsubscr...@googlegroups.com > 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 android-developers@googlegroups.com To unsubscribe from this group, send email to android-developers+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/android-developers?hl=en
Re: [android-developers] Re: [Help] how to draw multiple lines in Edittext?
It remind me of considering some margin space, so i change my code as below: protected void onDraw(Canvas canvas) { canvas.drawColor(paperColor); int count = getLineCount(); int height = this.getMeasuredHeight(); int line_height = this.getLineHeight(); int page_size = height / line_height + 1; if (count < page_size) { count = page_size; } * int posY = 5; // i guess the margin-top may be 5 px :)* for (int i = 1; i < count; i++) { *posY += line_height;* canvas.drawLine(0, posY, getRight(), posY, linePaint); canvas.save(); } super.onDraw(canvas); canvas.restore(); } finally it looks right, so i'm sure there is a margin space between my EditText and the default view , but i have no idea about how to get this height? so i hard code it 5 px any suggestion? -- You received this message because you are subscribed to the Google Groups "Android Developers" group. To post to this group, send email to android-developers@googlegroups.com To unsubscribe from this group, send email to android-developers+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/android-developers?hl=en
Re: [android-developers] Re: [Help] how to draw multiple lines in Edittext?
On Fri, May 7, 2010 at 9:45 PM, social hub wrote: > I believe you should include the height of your title bar and status bar as > well. If you account for one of them i guess it will look right > > hi, thanks for your reply. so getMeasuredHeight() return me the whole view height, which means getMeasuredHeight() = statusbar + title bar + my edit text? -- You received this message because you are subscribed to the Google Groups "Android Developers" group. To post to this group, send email to android-developers@googlegroups.com To unsubscribe from this group, send email to android-developers+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/android-developers?hl=en
Re: [android-developers] Re: [Help] how to draw multiple lines in Edittext?
I believe you should include the height of your title bar and status bar as well. If you account for one of them i guess it will look right On Fri, May 7, 2010 at 6:54 AM, Vincent Tsao wrote: > any help? > > > -- > You received this message because you are subscribed to the Google > Groups "Android Developers" group. > To post to this group, send email to android-developers@googlegroups.com > To unsubscribe from this group, send email to > android-developers+unsubscr...@googlegroups.com > 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 android-developers@googlegroups.com To unsubscribe from this group, send email to android-developers+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/android-developers?hl=en
[android-developers] Re: [Help] how to draw multiple lines in Edittext?
any help? > -- You received this message because you are subscribed to the Google Groups "Android Developers" group. To post to this group, send email to android-developers@googlegroups.com To unsubscribe from this group, send email to android-developers+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/android-developers?hl=en