android - textView 中缺少一些布局属性

标签 android android-layout android-constraintlayout

我正在我的 textView 中寻找一些属性,例如 layoutCenteringParent,但找不到它们。我想找到该特定属性以使文本居中(我正在学习在线教程)。我试着听从这里的建议: Missing attributes in the layout design - Android Studio

并删除了我的 Android studio 缓存,但没有帮助。 我是初学者,所以很有可能我只是在这里遗漏了一些东西。我附上截图:

enter image description here

最佳答案

使用 ConstraintLayout,您应该从所有四个边约束 Textview 使其居中。

<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
        xmlns:app="http://schemas.android.com/apk/res-auto"
        android:layout_width="match_parent"
        android:layout_height="match_parent">

        <TextView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="ABC"
            app:layout_constraintBottom_toBottomOf="parent"
            app:layout_constraintEnd_toEndOf="parent"
            app:layout_constraintStart_toStartOf="parent"
            app:layout_constraintTop_toTopOf="parent" />
    </androidx.constraintlayout.widget.ConstraintLayout>

关于android - textView 中缺少一些布局属性,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57475894/

相关文章:

java - 无法在尚未调用 Looper.prepare() android 服务的线程内创建处理程序

android - 从乐器中提取音频以找到音符

android - Textview maxlines 取决于它的高度

java - ConstraintLayout背景

php 只检索数字,即使是字符串

java - 当我们有 OkHttp 时为什么要使用 Retrofit

android - 一次查看包含 3 个项目的寻呼机

Android: Activity 启动时发生奇怪的崩溃。处理 XML 布局排序

android - 单击按钮更改 fragment View

android - 如何在 constraintlayout 中将 View 放置到与另一个 View 的特定偏移量