Android: Calculating the bounds of text

Source: Internet
Author: User

Package Cc.makeblock.mzero;import Cc.makeblock.android.utils.loger;import Cc.makeblock.global.global;import Cc.makeblock.widget.mbbuttoncircular;import Cc.makeblock.widget.mbbuttonwithicon;import Cc.makeblock.widget.mbchartview;import Cc.makeblock.widget.mbdiodeviewwithicon;import Cc.makeblock.widget.mbdirectionview;import Cc.makeblock.widget.mbonseekbarchangelistener;import Cc.makeblock.widget.mbseekbar;import Cc.makeblock.widget.mbseekbarnoicon;import Cc.makeblock.widget.mbdirectionview.mbondirectionchangedlistener;import Cc.makeblock.widget.mbdiodeview;import Cc.makeblock.widget.mbcomplicatedview;import Cc.makeblock.widget.mbseekbarwithicon;import Cc.makeblock.widget.testtextbounds;import Android.content.context;import Android.graphics.color;import Android.os.bundle;import Android.view.motionevent;import Android.view.view;import android.widget.RelativeLayout; public class Testactivity extends Baseactivity {protected static final String TAG = "testavtivity"; Relativelayout Root_relativElayout; Context context; Mbcomplicatedview Complicateview; Mbdiodeview Diodeview; Mbdirectionview Corsignview; Mbchartview ChartView; @Overrideprotected void OnCreate (Bundle savedinstancestate) {super.oncreate ( Savedinstancestate); Setcontentview (r.layout.activity_test); context = this; Global.init (this); root_relativelayout = (relativelayout) Findviewbyid (r.id.root_relativelayout); SETUPCUSTOMVIEW6 ( );} private void Setupcustomview () {//complicateview = new Mbcomplicatedview (this); Complicateview.setbackgroundresource ( r.drawable.bg); Relativelayout.layoutparams rellayoutparams = new Relativelayout.layoutparams (Complicateview.getmbwidth (), Complicateview.getmbheight ()); Rellayoutparams.addrule (Relativelayout.align_parent_left); Rellayoutparams.addrule (relativelayout.align_parent_top); int TOP = 200;int left = 300;rellayoutparams.setmargins ( Left, top, 0, 0); Root_relativelayout.addview (complicateview,rellayoutparams);} private void SetupCustomView2 () {//diodeview = new Mbdiodeview (this);//Diodeview.setbacKgroundresource (r.drawable.bg);d Iodeview.setbackgroundcolor (Color.White); Relativelayout.layoutparams rellayoutparams = new Relativelayout.layoutparams (Diodeview.getmbwidth (), Diodeview.getmbheight ()); Rellayoutparams.addrule (Relativelayout.align_parent_left); RelLayoutParams.addRule ( relativelayout.align_parent_top); int TOP = 200;int left = 300;rellayoutparams.setmargins (left, TOP, 0, 0); root_ Relativelayout.addview (diodeview,rellayoutparams);} private void SetupCustomView3 () {//corsignview = new Mbdirectionview (this);//Diodeview.setbackgroundresource ( r.drawable.bg); Corsignview.setbackgroundcolor (Color.White); corsignview.setmbmovable (false); Relativelayout.layoutparams rellayoutparams = new Relativelayout.layoutparams (Corsignview.getmbwidth (), Corsignview.getmbheight ()); Rellayoutparams.addrule (Relativelayout.align_parent_left); RelLayoutParams.addRule ( relativelayout.align_parent_top); int TOP = 200;int left = 300;rellayoutparams.setmargins (left, TOP, 0, 0); root_ Relativelayout.addview (CorsignvieW,rellayoutparams); Corsignview.setmbondirectionchangedlistener (new Mbondirectionchangedlistener () {@ overridepublic void ondirectionchanged (int direction, int actiontype) {switch (actiontype) {case Motionevent.action_ DOWN:LOGER.E (Tag, "Action_down"); break;case MOTIONEVENT.ACTION_MOVE:LOGER.E (Tag, "Action_move"); break;case MOTIONEVENT.ACTION_UP:LOGER.E (TAG, "action_up"); switch (direction) {case MBDIRECTIONVIEW.DIRECTION_LEFT:LOGER.E (TAG, "Direction_left"); break;case MBDIRECTIONVIEW.DIRECTION_RIGHT:LOGER.E (TAG, "direction_right"); Break;case MBDIRECTIONVIEW.DIRECTION_TOP:LOGER.E (Tag, "direction_top"); break;case MBDIRECTIONVIEW.DIRECTION_BOTTOM:LOGER.E (Tag, "Direction_bottom"); break;case MBDIRECTIONVIEW.DIRECTION_UNKNOWN:LOGER.E (TAG, "Direction_unknown"); break;}}); private void SetupCustomView4 () {//chartview = new Mbchartview (this); Chartview.setbackgroundresource (r.drawable.bg) ;//chartview.setbackgroundcolor (Color.White); Relativelayout.layoutparams rellayoutparams = new RelativelayOut. Layoutparams (Chartview.getmbwidth (), Chartview.getmbheight ()); Rellayoutparams.addrule (RelativeLayout.ALIGN_ Parent_left); Rellayoutparams.addrule (relativelayout.align_parent_top); int TOP = 200;int left = 300; Rellayoutparams.setmargins (left, top, 0, 0); Root_relativelayout.addview (chartview,rellayoutparams);} public void OnClick2 (View v) {complicateview.setmbmovable (!complicateview.getmbmovable ()); Complicateview.setprogress (Complicateview.getprogress () +0.1f); Complicateview.setdiodedatanumber ((int) ( Complicateview.getprogress () *100); Complicateview.setlefticonresource (R.drawable.control_display_progress_bar_ icon);} public void OnClick (View v) {complicateview.setprogress (complicateview.getprogress () -0.1f); Complicateview.setdiodedatanumber ((int) (complicateview.getprogress () *100)); Complicateview.setlefticonresource ( R.DRAWABLE.CONTROL_JOYSTICK_01_BG);} private void SetupCustomView5 () {{Mbseekbarnoicon seekBar1 = new Mbseekbarnoicon (context, Mbseekbarnoicon.style_ Horizontal_long, 1); Seekbar1.setbackGroundresource (r.drawable.bg); seekbar1.setmbmovable (false); Relativelayout.layoutparams rellayoutparams = new Relativelayout.layoutparams (Seekbar1.getmbwidth (), Seekbar1.getmbheight ()); rellayoutparams.setmargins (0, 0); Root_relativelayout.addview (SEEKBAR1, Rellayoutparams);} {Mbseekbarnoicon seekBar2 = new Mbseekbarnoicon (context, mbseekbarnoicon.style_horizontal_short, 1); Seekbar2.setbackgroundresource (r.drawable.bg); seekbar2.setmbmovable (false); Relativelayout.layoutparams rellayoutparams = new Relativelayout.layoutparams (Seekbar2.getmbwidth (), Seekbar2.getmbheight ()); rellayoutparams.setmargins (0, 0); Root_relativelayout.addview (SEEKBAR2, Rellayoutparams); Seekbar2.setmbonseekbarchangelistener (new Mbonseekbarchangelistener () {@Overridepublic void Onprogresschanged (Mbseekbar Mbseekbar, float progress) {LOGER.E (TAG, "onprogresschanged:progress=" +progress);} @Overridepublic void Onstarttrackingtouch (Mbseekbar mbseekbar) {LOGER.E (TAG, "onstarttrackingtouch:mbseekbar=" + Mbseekbar);}@Overridepublic void Onstoptrackingtouch (Mbseekbar mbseekbar) {LOGER.E (TAG, "onstoptrackingtouch:mbseekbar=" + Mbseekbar);}});} {Mbseekbarnoicon seekBar3 = new Mbseekbarnoicon (context, Mbseekbarnoicon.style_vertical_long, 1); Seekbar3.setbackgroundresource (r.drawable.bg); Relativelayout.layoutparams rellayoutparams = new Relativelayout.layoutparams (Seekbar3.getmbwidth (), Seekbar3.getmbheight ()); Rellayoutparams.setmargins (420, 0, 0); Root_relativelayout.addview (SEEKBAR3, Rellayoutparams);} {Mbseekbarnoicon SEEKBAR4 = new Mbseekbarnoicon (context, mbseekbarnoicon.style_vertical_short, 1); Seekbar4.setbackgroundresource (r.drawable.bg); Relativelayout.layoutparams rellayoutparams = new Relativelayout.layoutparams (Seekbar4.getmbwidth (), Seekbar4.getmbheight ()); Rellayoutparams.setmargins (620, 0, 0); Root_relativelayout.addview (SEEKBAR4, Rellayoutparams);} {Mbseekbarwithicon SEEKBAR5 = new Mbseekbarwithicon (context, mbseekbarwithicon.style_horizontal_long_motor, 1); Seekbar5.setmbmovable (false); seekBar5.setbackgroundresource (r.drawable.bg); Relativelayout.layoutparams rellayoutparams = new Relativelayout.layoutparams (Seekbar5.getmbwidth (), Seekbar5.getmbheight ()); Rellayoutparams.setmargins (420, 620, 0, 0); Root_relativelayout.addview (SEEKBAR5, Rellayoutparams); Seekbar5.setmbonseekbarchangelistener (new Mbonseekbarchangelistener () {@Overridepublic void Onprogresschanged (Mbseekbar Mbseekbar, float progress) {LOGER.E (TAG, "onprogresschanged:progress=" +progress);} @Overridepublic void Onstarttrackingtouch (Mbseekbar mbseekbar) {LOGER.E (TAG, "onstarttrackingtouch:mbseekbar=" + Mbseekbar);} @Overridepublic void Onstoptrackingtouch (Mbseekbar mbseekbar) {LOGER.E (TAG, "onstoptrackingtouch:mbseekbar=" + Mbseekbar);}});} {Mbseekbarwithicon SEEKBAR6 = new Mbseekbarwithicon (context, mbseekbarwithicon.style_horizontal_long_diode, 1); Seekbar6.setmbmovable (false);//seekbar6.setbackgroundresource (r.drawable.bg); Relativelayout.layoutparams rellayoutparams = new Relativelayout.layoutparams (Seekbar6.getmbwidth (), Seekbar6.getmbheight ()); Rellayoutparams.setmargins (620, 720, 0, 0); Root_relativelayout.addview (SEEKBAR6, Rellayoutparams); Seekbar6.setmbonseekbarchangelistener (new Mbonseekbarchangelistener () {@Overridepublic void Onprogresschanged (Mbseekbar Mbseekbar, float progress) {LOGER.E (TAG, "onprogresschanged:progress=" +progress);} @Overridepublic void Onstarttrackingtouch (Mbseekbar mbseekbar) {LOGER.E (TAG, "onstarttrackingtouch:mbseekbar=" + Mbseekbar);} @Overridepublic void Onstoptrackingtouch (Mbseekbar mbseekbar) {LOGER.E (TAG, "onstoptrackingtouch:mbseekbar=" + Mbseekbar);}});} {Mbbuttonwithicon button = new Mbbuttonwithicon (context, mbbuttonwithicon.style_red, 2); button.setmbmovable (false); Relativelayout.layoutparams rellayoutparams = new Relativelayout.layoutparams (Button.getmbwidth (), Button.getmbheight ()); Rellayoutparams.setmargins (1520, 0, 0); Root_relativelayout.addview (Button, Rellayoutparams);} {Mbbuttonwithicon button = new Mbbuttonwithicon (context, Mbbuttonwithicon.style_green, 2); ButtoN.setmbmovable (FALSE); Relativelayout.layoutparams rellayoutparams = new Relativelayout.layoutparams (Button.getmbwidth (), Button.getmbheight ()); Rellayoutparams.setmargins (1520, 0, 0); Root_relativelayout.addview (Button, Rellayoutparams);} {Mbbuttonwithicon button = new Mbbuttonwithicon (context, mbbuttonwithicon.style_blue, 2); button.setmbmovable (false); Relativelayout.layoutparams rellayoutparams = new Relativelayout.layoutparams (Button.getmbwidth (), Button.getmbheight ()); Rellayoutparams.setmargins (1520, 0, 0); Root_relativelayout.addview (Button, Rellayoutparams);} {Mbbuttonwithicon button = new Mbbuttonwithicon (context, Mbbuttonwithicon.style_button, 2); Button.setmbmovable (False ); Relativelayout.layoutparams rellayoutparams = new Relativelayout.layoutparams (Button.getmbwidth (), Button.getmbheight ()); Rellayoutparams.setmargins (1520, 0, 0); Root_relativelayout.addview (Button, Rellayoutparams);} {Mbbuttonwithicon button = new Mbbuttonwithicon (context, Mbbuttonwithicon.style_buzzer, 2); button.setmbmovable (false); Relativelayout.layoutparams rellayoutparams = new Relativelayout.layoutparams (Button.getmbwidth (), Button.getmbheight ()); Rellayoutparams.setmargins (1520, 0, 0); Root_relativelayout.addview (Button, Rellayoutparams);} {Mbdiodeview Diodeview = new Mbdiodeview (context, 1);d iodeview.setmbmovable (false); Relativelayout.layoutparams rellayoutparams = new Relativelayout.layoutparams (Diodeview.getmbwidth (), Diodeview.getmbheight ()); Rellayoutparams.setmargins (1020, 0, 0); Root_relativelayout.addview (DiodeView, Rellayoutparams);} {Mbdiodeviewwithicon Diodeview = new Mbdiodeviewwithicon (context, mbdiodeviewwithicon.style_custom, 1); Diodeview.setmbmovable (FALSE); Relativelayout.layoutparams rellayoutparams = new Relativelayout.layoutparams (Diodeview.getmbwidth (), Diodeview.getmbheight ()); Rellayoutparams.setmargins (1020, 0, 0, 0); Root_relativelayout.addview (DiodeView, Rellayoutparams);} {Mbdiodeviewwithicon Diodeview = new Mbdiodeviewwithicon (context, Mbdiodeviewwithicon.Style_ultrasonic, 1);d iodeview.setmbmovable (false); Relativelayout.layoutparams rellayoutparams = new Relativelayout.layoutparams (Diodeview.getmbwidth (), Diodeview.getmbheight ()); Rellayoutparams.setmargins (1020, 0, 0); Root_relativelayout.addview (DiodeView, Rellayoutparams);} {Mbdiodeviewwithicon Diodeview = new Mbdiodeviewwithicon (context, mbdiodeviewwithicon.style_brightness, 1); Diodeview.setmbmovable (FALSE); Relativelayout.layoutparams rellayoutparams = new Relativelayout.layoutparams (Diodeview.getmbwidth (), Diodeview.getmbheight ()); Rellayoutparams.setmargins (1020, 0, 0); Root_relativelayout.addview (DiodeView, Rellayoutparams);} {Mbdiodeviewwithicon Diodeview = new Mbdiodeviewwithicon (context, mbdiodeviewwithicon.style_sound, 1); Diodeview.setmbmovable (FALSE); Relativelayout.layoutparams rellayoutparams = new Relativelayout.layoutparams (Diodeview.getmbwidth (), Diodeview.getmbheight ()); Rellayoutparams.setmargins (1020, 0, 0); Root_relativelayout.addview (DiodeView, Rellayoutparams);}{mbdiodeviewwithicon Diodeview = new Mbdiodeviewwithicon (context, mbdiodeviewwithicon.style_temperature, 1); Diodeview.setmbmovable (FALSE); Relativelayout.layoutparams rellayoutparams = new Relativelayout.layoutparams (Diodeview.getmbwidth (), Diodeview.getmbheight ()); Rellayoutparams.setmargins (1020, 0, 0); Root_relativelayout.addview (DiodeView, Rellayoutparams);} {}}private void SetupCustomView6 () {//testtextbounds Diodeview = new Testtextbounds (context);// Relativelayout.layoutparams rellayoutparams = new Relativelayout.layoutparams (700, 300);// Rellayoutparams.setmargins (ten, 0, 0);//root_relativelayout.addview (Diodeview,rellayoutparams); View SubView = new view (context); Subview.setbackgroundcolor (color.red); Relativelayout.layoutparams rellayoutparams = new Relativelayout.layoutparams (n.); Rellayoutparams.setmargins ( 0, 0); Root_relativelayout.addview (SubView, rellayoutparams);} public void OnClick2 (View v) {//diodeview.setdiodedatanumber (Diodeview.getdiodedatanumber () +120);//}////public void OnClick (View v) {//diodeview.setdiodedatanumber (Diodeview.getdiodedatanumber ()-110);/}} 

  

Android: Calculating the bounds of text

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.