Android的 - 如何画一个字母一个具体点吗? [英] Android - How to draw a letter at a specific point?

查看:114
本文介绍了Android的 - 如何画一个字母一个具体点吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我要填满屏幕,在随机位置的100个不同的字母。在iPhone上我刚刚创建了一堆UILabels的设置其x和y位置,然后用动画移动至约。

在Android上它并不像我可以添加一个TextView我的看法,并指定其X和Y有没有办法做到这一点?

 查看gameView = findViewById(R.id.gameboard);
    电视=新的TextView(gameView.getContext());
    tv.setText(A);
    tv.setWidth(瓦特); tv.setHeight(H);
    //如何设置X和Y?
 

编辑:解决的办法是使用AbsoluteLayout:

  AbsoluteLayout人=(AbsoluteLayout)findViewById(R.id.gb_layout);
    电视=新的TextView(本);
    AbsoluteLayout.LayoutParams PARAMS =新AbsoluteLayout.LayoutParams(
            AbsoluteLayout.LayoutParams.WRAP_CONTENT,
            AbsoluteLayout.LayoutParams.WRAP_CONTENT,10,10);
    params.x = 50;
    params.y = 50;
    al.addView(电视,则params);
 

和移动它的基础上MotionEvent我:

  AbsoluteLayout.LayoutParams P =新AbsoluteLayout.LayoutParams(
            AbsoluteLayout.LayoutParams.WRAP_CONTENT,
            AbsoluteLayout.LayoutParams.WRAP_CONTENT,(int)的me.getX(),(int)的me.getY());
    mTV.setLayoutParams(对);
 

解决方案

我不完全相信你如何去在code这样做,但你需要使用一个绝对布局的根元素。 (编辑:不要使用绝对布局,因为它指出,这是pcated德$ P $最接近的替代方案似乎是RelativeLayout的)

在XML格式的绝对布局坐标的属性是layout_x和layout_y

编辑:一个小小的研究是说,你需要使用setLayoutParams,但我的Eclipse IDE中工作不正常,所以很遗憾我不能测试你在寻找什么

I want to fill the screen with a 100 different letters in random positions. On the iPhone I just created a bunch of UILabels set their x and y positions and then used animations to move them about.

On Android it doesn't look like I can add a TextView to my view and specify its X and Y. Is there a way to do this?

    View gameView = findViewById(R.id.gameboard);
    tv = new TextView(gameView.getContext());
    tv.setText("A");
    tv.setWidth(w); tv.setHeight(h);
    // How to set the X and Y?

EDIT: The solution was to use AbsoluteLayout:

    AbsoluteLayout al = (AbsoluteLayout)findViewById(R.id.gb_layout);
    tv = new TextView(this);
    AbsoluteLayout.LayoutParams params = new AbsoluteLayout.LayoutParams(
            AbsoluteLayout.LayoutParams.WRAP_CONTENT,
            AbsoluteLayout.LayoutParams.WRAP_CONTENT,10,10);        
    params.x = 50;
    params.y = 50;
    al.addView(tv, params);

and to move it base on MotionEvent me:

    AbsoluteLayout.LayoutParams p = new AbsoluteLayout.LayoutParams(
            AbsoluteLayout.LayoutParams.WRAP_CONTENT,
            AbsoluteLayout.LayoutParams.WRAP_CONTENT,(int)me.getX(), (int)me.getY());
    mTV.setLayoutParams (p);

解决方案

I'm not entirely sure how you'd go about doing this in code, but you need to use an absolute layout as your root element. (edit: Do not use absolute layout, as it was pointed out that it is deprecated. The closest alternative seems to be RelativeLayout.)

The properties in the XML format for the absolute layout coordinates are layout_x and layout_y.

edit: A little research is saying you need to be using setLayoutParams, but my Eclipse IDE is not working properly, so unfortunately I can't test exactly what you're looking for.

这篇关于Android的 - 如何画一个字母一个具体点吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆