Android and Layouts

后端 未结 2 1010
南方客
南方客 2021-01-03 09:25

I need to locate text on view:

text \'Some more text\' should be located in bottom|center_horizontal

text \'Short text\' should be located on with align righ

2条回答
  •  天涯浪人
    2021-01-03 09:53

    If I understand correctly you want to simply put a serious of strings on the text view. You can do this in XML. A handy GUI tool for this would be DroidDraw You can run it in a browser or on your Desktop. I find it handy for some GUI things. Other than that you can Draw a view, something like this...

       class DrawOnTop extends View { 
        public DrawOnTop(Context context) { 
                super(context); 
                // TODO Auto-generated constructor stub 
        } 
        @Override 
        public void onDraw(Canvas canvas) { 
            Paint paint = new Paint(); 
                paint.setStyle(Paint.Style.FILL); 
                paint.setColor(Color.RED);
                paint.setTextSize(15);
                Paint paint2 = new Paint();
                canvas.drawText("Test", 30, 30, paint);
        } 
    } 
    

    In the above example I've defined a new paint. This is to set the properties of the text. I've given it a red colour and text size 15. You can add more attributes too. I've also drawn a string "Test". It is at coordinates (30,30) these are the x and y coordinates where I want Java to draw it. It's then using paint's attributes.

    EDIT: this page may also be of some help http://developer.android.com/reference/android/graphics/Canvas.html

提交回复
热议问题