How to right-align text in an Android TextView or

2019-02-07 15:46发布

I have an EditText in my application. I want to align the text in it to the right instead of the default left. I tried adding

android:layout_gravity="right"

but this doesn't seem to work. any other suggestions please?

4条回答
爷、活的狠高调
2楼-- · 2019-02-07 16:17

You may use android:layout_alignParentRight="true" to align the EditText's right edge to its parent's right edge. Also, if you really want to use the layout_gravity or gravity attributes, check out this article that discusses the proper use of them.

查看更多
Explosion°爆炸
3楼-- · 2019-02-07 16:21

layout_gravity means that you are specifying the layouts attribute, not the element inside. In some conditions, such as layout_width and layout_height is wrap_content, layout specifications can give what you want about the element inisde your layout, since the boundries of the layout and the element (not elements) are the same..

查看更多
我想做一个坏孩纸
4楼-- · 2019-02-07 16:31

You should use android:gravity="right". layout_gravity is for the view (EditText) alignment against the container.

查看更多
来,给爷笑一个
5楼-- · 2019-02-07 16:36

You can jst set property for edit text in property window i.e. Gravity to right or by adding code of lin e in xml file of UI : android:gravity="right"

查看更多
登录 后发表回答