gpt4 book ai didi

android - TextView不靠右

转载 作者:行者123 更新时间:2023-11-29 16:47:02 25 4
gpt4 key购买 nike

我想将 TextView 固定在右上角。

我的代码是:

<?xml version="1.0" encoding="utf-8"?>
<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"
tools:context="Test.test.MainActivity">

<FrameLayout
android:id="@+id/fragmentContainer"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_marginTop="42dp"/>

<TextView
android:id="@+id/textView1"
android:layout_width="wrap_content"
android:layout_height="42dp"
android:layout_marginRight="0dp"
android:text="@string/Title1"
android:textSize="30dp" />

</android.support.constraint.ConstraintLayout>

我尝试设置 TextView:

  • android:layout_alignParentRight="true"
  • android:layout_marginRight="0dp"
  • android:layout_marginTop="0dp"

但没有任何效果,TextView 留在左上角。

有人有解决方案吗?

更新:

如何将左侧 TextView 粘贴到另一个粘贴到右侧父级的 TextView

我尝试设置怀特但没有..

<TextView
android:id="@+id/textView1"
android:layout_width="wrap_content"
android:layout_weight="0"
android:layout_height="42dp"
app:layout_constraintRight_toRightOf="parent"
android:text="@string/Title1"
android:textSize="30dp" />

<TextView
android:id="@+id/textView2"
android:layout_width="wrap_content"
android:layout_weight="1"
android:layout_height="42dp"
app:layout_constraintRight_toRightOf="parent"
android:text="@string/Title2"
android:textSize="30dp" />

我希望 textView2 会粘在左边的 textView1 上。

查找要更新的解决方案我只是在textview2中设置

  • app:layout_constraintBaseline_toBaselineOf="@+id/textView1"

  • app:layout_constraintEnd_toStartOf="@+id/textView1"

谢谢,

塔尔

最佳答案

在Constraint Layout中,将TextView的右约束设置到父布局的右侧,使其右对齐

将以下约束添加到您的 TextView

app:layout_constraintRight_toRightOf="parent"

像这样

<TextView
android:id="@+id/textViewHowMuchSigned"
android:layout_width="wrap_content"
android:layout_height="42dp"
app:layout_constraintRight_toRightOf="parent"
android:text="@string/Title"
android:textSize="30dp" />

关于android - TextView不靠右,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47616758/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com