[英]issue with layout textview alignment
I've tried all the layouts but I still have the same problem. 我已经尝试了所有布局,但是仍然遇到相同的问题。 I want to align a TextView horizontally but nothing works.
我想水平对齐TextView,但是没有任何效果。 In all the layouts available, none has worked.
在所有可用的布局中,没有一个起作用。 Always having the same picture.
总是有相同的图片。 It's like having a block on the right that blocks everything.
就像在右侧有一个块将所有内容挡住一样。
Image describing the situation 描述情况的图像
Can someone help please? 有人可以帮忙吗?
Try do it with constraint layout. 尝试使用约束布局。
Example first: 首先示例:
<android.support.constraint.ConstraintLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent">
<TextView
android:id="@+id/textView20"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginEnd="8dp"
android:layout_marginStart="8dp"
android:layout_marginTop="8dp"
android:text="TextView"
android:gravity="center"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
</android.support.constraint.ConstraintLayout>
second example: 第二个例子:
<android.support.constraint.ConstraintLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent">
<TextView
android:id="@+id/textView20"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginEnd="8dp"
android:layout_marginStart="8dp"
android:layout_marginTop="8dp"
android:text="TextView"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
</android.support.constraint.ConstraintLayout>
try to use 尝试使用
android:layout_gravity="center_horizontal"
this will tell Android to align your TextView to align in center horizontally. 这将告诉Android对齐您的TextView,使其水平居中对齐。
Example 例
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
/>
Also, share your xml code so I can rectify it 另外,分享您的xml代码,以便我进行纠正
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.