开发者

How to poistion edittext in program in android?

I am dynamically creating an Editext in my code. i want to position it in my x and y position in my code itself in an a开发者_如何学Pythonbsolute layout. can anyone help me to do this.


Don't use AbsoluteLayout. It's deprecated, and just a bad idea, as it will look differently on screens with different DPIs. Consider using a RelativeLayout instead. If you can give a more specific problem, we can recommend an alternative solution.

Keeping in mind that you shouldn't actually use this, and that using AbsoluteLayout has been indirectly linked to causing cancer, and may also lead to psychosis, here is how you would do this in code assuming you have an AbsoluteLayout with a child EditText in an XML layout:

EditText editText = (EditText)findViewById(R.id.my_edit_text);
AbsoluteLayout.LayoutParams abs_params = 
    new AbsoluteLayout.LayoutParams(
        //width in pixels, or AbsoluteLayout.FILL_PARENT/WRAP_CONTENT
        60,
        //height in pixels, or AbsoluteLayout.FILL_PARENT/WRAP_CONTENT
        30,
        //x position with regards to the origin
        10,
        //y position with regards to the origin
        10
    );
editText.setLayoutParams(abs_params);

Here are some documentation pages to review: http://developer.android.com/reference/android/widget/AbsoluteLayout.LayoutParams.html http://developer.android.com/reference/android/widget/AbsoluteLayout.html http://developer.android.com/reference/android/widget/EditText.html

I am not responsible for any trauma that may occur as a result of using an AbsoluteLayout. May god have mercy on your soul. :)

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜