gpt4 book ai didi

android - TextViews不在约束布局中移至“开始”位置

转载 作者:行者123 更新时间:2023-12-02 13:40:32 27 4
gpt4 key购买 nike

由于某种原因,我的TextViews中的ConstraintLayout根本不会移动,并停留在中间。如何将它们移到“左/开始”位置?我尝试了以下方法,但是这些都不起作用。关于还可以使用什么的任何想法?

  • android:gravity="start"
  • app:flow_horizontalBias="0.0"

  • enter image description here
    <?xml version="1.0" encoding="utf-8"?>
    <androidx.cardview.widget.CardView
    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="wrap_content"
    app:cardUseCompatPadding="true">

    <LinearLayout
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:orientation="vertical"
    android:id="@+id/linearLayoutB"
    android:foreground="?android:attr/selectableItemBackground">

    <!--Constraint 1-->
    <androidx.constraintlayout.widget.ConstraintLayout
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:id="@+id/constraintLayoutBTitle"
    android:layout_marginBottom="10dp">

    <ImageButton
    android:id="@+id/ibB1"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    app:layout_constraintStart_toStartOf="parent"
    app:layout_constraintTop_toTopOf="parent"
    android:background="?attr/selectableItemBackgroundBorderless"/>

    <TextView
    android:id="@+id/tvB1"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    app:layout_constraintStart_toEndOf="@+id/ibB1"
    app:layout_constraintEnd_toEndOf="parent"
    app:layout_constraintTop_toTopOf="parent"
    app:layout_constrainedWidth="true"
    style="@android:style/TextAppearance.Medium"/>
    </androidx.constraintlayout.widget.ConstraintLayout>

    <!--Constraint 2-->
    <androidx.constraintlayout.widget.ConstraintLayout
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:id="@+id/constraintLayoutBContent">

    <ImageView
    android:id="@+id/ivB2"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    app:layout_constraintStart_toStartOf="parent"
    app:layout_constraintTop_toTopOf="parent"
    app:srcCompat="@mipmap/ic_launcher_round" />

    <TextView
    android:id="@+id/tvB2"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_marginStart="10dp"
    android:layout_marginBottom="10dp"
    app:flow_horizontalBias="0.0"
    app:layout_constraintStart_toEndOf="@+id/ivB2"
    app:layout_constraintEnd_toEndOf="parent"
    app:layout_constraintTop_toTopOf="@+id/ivB2"
    app:layout_constrainedWidth="true"
    style="@android:style/TextAppearance.Medium"/>

    <TextView
    android:id="@+id/tvB3"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_marginStart="10dp"
    android:layout_marginTop="10dp"
    android:layout_marginBottom="10dp"
    app:layout_constraintBottom_toTopOf="@+id/tvB4"
    app:layout_constraintStart_toEndOf="@+id/ivB2"
    app:layout_constraintEnd_toEndOf="parent"
    app:layout_constraintTop_toBottomOf="@+id/ivB2"
    app:layout_constrainedWidth="true"
    style="@android:style/TextAppearance.Medium"/>

    <ImageView
    android:id="@+id/ivB4"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    app:layout_constraintEnd_toEndOf="@+id/ivB2"
    app:layout_constraintStart_toStartOf="@+id/ivB2"
    app:layout_constraintTop_toBottomOf="@+id/ivB2"
    app:layout_constraintTop_toTopOf="@+id/tvB4"
    app:srcCompat="@mipmap/ic_launcher_round" />

    <TextView
    android:id="@+id/tvB4"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_marginStart="10dp"
    app:layout_constraintStart_toEndOf="@+id/ivB4"
    app:layout_constraintEnd_toEndOf="parent"
    app:layout_constraintTop_toBottomOf="@+id/tvB3"
    app:layout_constraintTop_toTopOf="@+id/ivB4"
    app:layout_constrainedWidth="true"
    style="@android:style/TextAppearance.Medium"/>
    </androidx.constraintlayout.widget.ConstraintLayout>
    </LinearLayout>
    </androidx.cardview.widget.CardView>

    最佳答案

    在这里,我只是对0.0设置了偏见。

    <?xml version="1.0" encoding="utf-8"?>
    <androidx.cardview.widget.CardView 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="wrap_content"
    app:cardUseCompatPadding="true">

    <LinearLayout
    android:id="@+id/linearLayoutB"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:foreground="?android:attr/selectableItemBackground"
    android:orientation="vertical">

    <!--Constraint 1-->
    <androidx.constraintlayout.widget.ConstraintLayout
    android:id="@+id/constraintLayoutBTitle"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:layout_marginBottom="10dp">

    <ImageButton
    android:id="@+id/ibB1"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:background="?attr/selectableItemBackgroundBorderless"
    app:layout_constraintStart_toStartOf="parent"
    app:layout_constraintTop_toTopOf="parent" />

    <TextView
    android:id="@+id/tvB1"
    style="@android:style/TextAppearance.Medium"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    app:layout_constrainedWidth="true"
    app:layout_constraintEnd_toEndOf="parent"
    app:layout_constraintStart_toEndOf="@+id/ibB1"
    app:layout_constraintTop_toTopOf="parent" />
    </androidx.constraintlayout.widget.ConstraintLayout>

    <!--Constraint 2-->
    <androidx.constraintlayout.widget.ConstraintLayout
    android:id="@+id/constraintLayoutBContent"
    android:layout_width="match_parent"
    android:layout_height="match_parent">

    <ImageView
    android:id="@+id/ivB2"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    app:layout_constraintStart_toStartOf="parent"
    app:layout_constraintTop_toTopOf="parent"
    app:srcCompat="@mipmap/ic_launcher_round" />

    <TextView
    android:id="@+id/tvB2"
    style="@android:style/TextAppearance.Medium"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_marginStart="10dp"
    app:layout_constrainedWidth="true"
    app:layout_constraintEnd_toEndOf="parent"
    app:layout_constraintHorizontal_bias="0.0"
    app:layout_constraintStart_toEndOf="@+id/ivB2"
    app:layout_constraintTop_toTopOf="@+id/ivB2"
    tools:text="2a" />

    <TextView
    android:id="@+id/tvB3"
    style="@android:style/TextAppearance.Medium"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_marginStart="10dp"
    android:layout_marginTop="10dp"
    android:layout_marginBottom="10dp"
    app:layout_constrainedWidth="true"
    app:layout_constraintBottom_toTopOf="@+id/tvB4"
    app:layout_constraintEnd_toEndOf="parent"
    app:layout_constraintHorizontal_bias="0.0"
    app:layout_constraintStart_toEndOf="@+id/ivB2"
    app:layout_constraintTop_toBottomOf="@+id/ivB2"
    tools:text="2b" />

    <ImageView
    android:id="@+id/ivB4"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    app:layout_constraintEnd_toEndOf="@+id/ivB2"
    app:layout_constraintStart_toStartOf="@+id/ivB2"
    app:layout_constraintTop_toBottomOf="@+id/ivB2"
    app:layout_constraintTop_toTopOf="@+id/tvB4"
    app:srcCompat="@mipmap/ic_launcher_round" />

    <TextView
    android:id="@+id/tvB4"
    style="@android:style/TextAppearance.Medium"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_marginStart="10dp"
    app:layout_constrainedWidth="true"
    app:layout_constraintEnd_toEndOf="parent"
    app:layout_constraintHorizontal_bias="0.0"
    app:layout_constraintStart_toEndOf="@+id/ivB4"
    app:layout_constraintTop_toBottomOf="@+id/tvB3"
    tools:text="2c" />
    </androidx.constraintlayout.widget.ConstraintLayout>

    </LinearLayout>

    </androidx.cardview.widget.CardView>
    结果:
    enter image description here

    但是我认为您在布局中添加了太多限制。您不必为每个textView将约束设置到卡片 View 的末尾。如果您只添加一个,它将自动开始。

    关于android - TextViews不在约束布局中移至“开始”位置,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/63837099/

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