Android:在左侧对齐文本并将文本视图居中在他的父母视图中 [英] Android : Align a text at left and center the textview in his parents view
问题描述
你好,我遇到了一个小问题
Hello i'm facing a little problem
我正在使用 GRAVITY LEFT 使我的文本对齐视图左侧,但我想在 textview 内居中,但也要在左侧对齐
I'm using GRAVITY LEFT to make my text an aligment for the left side of a view but I want to center inside the textview but also align on the left part
这是我现在所拥有的:
___________________________________
_ _ _ _ _ _| aaaaaaaaaaaaa |_ _ _ _ _ _
_ _ _ _ _ _| aaaaaaaa |_ _ _ _ _ _
_ _ _ _ _ _| aaaaaaaaaaaaaa |_ _ _ _ _ _
-----------------------------------
我想要的是:
___________________________________
_ _ _ _ _ _| aaaaaaaaaaa |_ _ _ _ _ _
_ _ _ _ _ _| aaaaaaaa |_ _ _ _ _ _
_ _ _ _ _ _| aaaaaaaaaaaaaa |_ _ _ _ _ _
-----------------------------------
地点:
_ _ _ _ = 文本视图之外
_ _ _ _ = outside of textview
|= TextView 边缘
| = the TextView edge
我试过 android:gravity = "left|center" 但它不起作用,知道吗?
I tried android:gravity = "left|center" but it doesn't work, any idea ?
谢谢
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="@+id/image_button_wrapper"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center"
android:layout_centerVertical="true">
<ImageView
android:id="@+id/left_button_image"
android:layout_centerVertical="true"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginRight="@dimen/spacing_normal"/>
<Textview
android:id="@+id/textview"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_toRightOf="@id/left_button_image"
android:gravity = "center|left|left"
android:clickable="false"
android:focusable="false"
app:font_name="Roboto-Light.ttf"/>
我所拥有的(文本左对齐但不居中)
What i've (text align left but not centered)
我想要什么(文本左对齐并居中)(我手动添加了一个填充以获得渲染,但它很脏并且不会适应所有文本):
What i want (text align left and centered) (I add a padding manually to get the render but it's dirty and will not adapt to all text) :
推荐答案
只给 Textview parent 为:
Just give Textview parent as:
android:gravity = "center"
只需将 Textview 设为:
Just give Textview as:
android:gravity = "center_vertical|left|start"
android:layout_margin="20dp"
这篇关于Android:在左侧对齐文本并将文本视图居中在他的父母视图中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!