【问题标题】:Android Studio Code Aligning Does not workAndroid Studio 代码对齐不起作用
【发布时间】:2018-03-08 16:55:04
【问题描述】:

我正在关注视频教程。在导师的电脑上,这两个文本视图正确对齐,但在我的电脑上却没有。请让我知道这有什么问题。 - 附上图片 - 。谢谢。

【问题讨论】:

  • 显示你的 layout.xml

标签: android android-layout textview


【解决方案1】:

当使用约束布局时,你需要为其提供一些约束。 这里添加到第二个 TextView:

layout_constraintLeft_toRightOf="@id/text_view_1"

【讨论】:

    【解决方案2】:
     xmlns:app="http://schemas.android.com/apk/res-auto"
    

    并使用

            app:layout_constraintLeft_toLeftOf="parent"
            app:layout_constraintTop_toTopOf="parent"
            app:layout_constraintRight_toRightOf="parent"
            app:layout_constraintBottom_toBottomOf="xyz"
    

    【讨论】:

      【解决方案3】:

      对齐文本的方法有很多,但您试图通过使用有点复杂的约束布局来实现这一点。

      这是一个使用 android:layout_toEndOf="" 的相对布局的示例,它只是用于将 TextView 推送到所需 Textview 的末尾:

      <?xml version="1.0" encoding="utf-8"?>
      <LinearLayout android:layout_height="match_parent" android:layout_width="match_parent"
          android:orientation="vertical"
          xmlns:android="http://schemas.android.com/apk/res/android">
      
      
          <RelativeLayout
              android:layout_width="match_parent"
              android:layout_height="30dp">
      
              <TextView
                  android:id="@+id/firstText"
                  android:layout_width="wrap_content"
                  android:layout_height="match_parent"
                  android:gravity="center"
                  android:layout_marginEnd="5dp"
                  android:text="FIRST TEXT" />
      
              <TextView
                  android:id="@+id/secondText"
                  android:layout_width="wrap_content"
                  android:layout_height="match_parent"
                  android:gravity="center"
                  android:layout_toEndOf="@id/firstText"
                  android:text="SECOND TEXT"/>
          </RelativeLayout>
      </LinearLayout>
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2017-08-19
        • 2020-12-05
        • 1970-01-01
        • 2021-10-22
        • 2015-03-30
        • 2012-06-11
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多