Android的TextView的文本将不会居中 [英] Android TextView text won't center
问题描述
我试图做一个PIN输入活动,但一个小东西是不是很为我工作。我不能让文字在TextView中的中心在截图的顶部位置:
I am trying to make a PIN entry activity, but one little thing is not quite working for me. I can't get the text to center in the TextView's at the top of the screenshot here:
它的工作方式是当用户输入PIN码,我将会把一个明星在每个TextView中可见反馈。问题是,我想明星为中心。我试图layout_gravity =中心,但它不会有所作为。这是我目前的布局:
The way it will work is when the user is entering a PIN, I will place a star in each TextView for visible feedback. The problem is, I want the star to be centered. I have tried layout_gravity="center", but it doesn't make a difference. Here's my current layout:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent">
<TextView
android:textAppearance="?android:attr/textAppearanceLarge"
android:layout_height="wrap_content"
android:id="@+id/textView1"
android:text="PIN Required"
android:layout_width="wrap_content"
android:layout_gravity="center_horizontal"
android:layout_marginBottom="12sp"
></TextView>
<LinearLayout
android:layout_width="match_parent"
android:id="@+id/linearLayout1"
android:layout_height="wrap_content"
android:layout_marginBottom="12sp"
android:layout_gravity="center_horizontal"
>
<TextView
android:id="@+id/text1"
android:layout_height="32sp"
android:layout_width="48sp"
android:layout_weight="1"
android:layout_marginRight="2sp"
android:layout_marginLeft="48sp"
android:background="#FFFFFF"
android:text="X"
android:layout_gravity="center"
></TextView>
<TextView
android:id="@+id/text2"
android:layout_height="32sp"
android:layout_width="48sp"
android:layout_weight="1"
android:layout_marginRight="2sp"
android:layout_marginLeft="2sp"
android:background="#FFFFFF"
></TextView>
<TextView
android:id="@+id/text3"
android:layout_height="32sp"
android:layout_width="48sp"
android:layout_weight="1"
android:layout_marginRight="2sp"
android:layout_marginLeft="2sp"
android:background="#FFFFFF"
></TextView>
<TextView
android:id="@+id/text4"
android:layout_height="32sp"
android:layout_width="48sp"
android:layout_weight="1"
android:layout_marginRight="48sp"
android:layout_marginLeft="2sp"
android:background="#FFFFFF"
></TextView>
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:id="@+id/linearLayout2"
android:layout_height="wrap_content"
android:layout_marginBottom="12sp"
>
<Button
android:text="1"
android:textColor="#FFFFFF"
android:id="@+id/button1"
android:layout_height="32sp"
android:layout_width="64sp"
android:layout_weight="1"
android:editable="false"
android:layout_marginRight="2sp"
android:layout_marginLeft="48sp"
android:background="@drawable/action_background_gradient"
android:onClick="ButtonClicked"
></Button>
<Button
android:text="2"
android:textColor="#FFFFFF"
android:id="@+id/button2"
android:layout_height="32sp"
android:layout_width="64sp"
android:layout_weight="1"
android:editable="false"
android:layout_marginRight="2sp"
android:layout_marginLeft="2sp"
android:background="@drawable/action_background_gradient"
android:onClick="ButtonClicked"
></Button>
<Button
android:text="3"
android:textColor="#FFFFFF"
android:id="@+id/button3"
android:layout_height="32sp"
android:layout_width="64sp"
android:layout_weight="1"
android:editable="false"
android:layout_marginRight="48sp"
android:layout_marginLeft="2sp"
android:background="@drawable/action_background_gradient"
android:onClick="ButtonClicked"
></Button>
</LinearLayout>
<!--... and so on for the rest of the buttons ... -->
</LinearLayout>
我有那个机器人:在有文字=X为先的TextView只是让我可以看到,如果这是工作。当我做了调整布局,即会自行消失。 有什么简单的事情,我缺少什么?
I've got that android:text="X" in there for the first textview just so I can see if it is working. When I am done tweaking the layout, that will go away. What simple thing am I missing?
推荐答案
使用安卓重力=中心
虽然我没有看到你的code任何的EditText元素。你确定你贴权code?
although I'm not seeing any EditText element in your code. You sure you posted the right code?
这篇关于Android的TextView的文本将不会居中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!