文本视图未移动到约束布局中的起始位置 由于某种原因,我的约束布局>代码> 文本视图< /代码>根本不会移动,卡在中间。如何将它们移动到左/起始位置?我尝试了以下方法,但都不起作用。还有什么好用的吗 android:gravity=“start” app:flow\u horizontalBias=“0.0”
文本视图未移动到约束布局中的起始位置 由于某种原因,我的约束布局>代码> 文本视图< /代码>根本不会移动,卡在中间。如何将它们移动到左/起始位置?我尝试了以下方法,但都不起作用。还有什么好用的吗 android:gravity=“start” app:flow\u horizontalBias=“0.0”,android,xml,kotlin,android-recyclerview,android-constraintlayout,Android,Xml,Kotlin,Android Recyclerview,Android Constraintlayout,如果你想得到类似的东西,请复制下面的代码 将textView置于左侧的关键是展开textView以匹配约束 <androidx.cardview.widget.CardView xmlns:android="http://schemas.android.com/apk/res/android" xmlns:app="http://schemas.android.com/apk/res-auto" android:layout
如果你想得到类似的东西,请复制下面的代码 将textView置于左侧的关键是展开textView以匹配约束
<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"
style="@android:style/TextAppearance.Medium"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="tvB1"
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="0dp"
android:layout_height="wrap_content"
android:layout_marginStart="10dp"
android:text="tvb2"
app:layout_constrainedWidth="true"
app:layout_constraintBottom_toBottomOf="@+id/ivB2"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toEndOf="@+id/ivB2"
app:layout_constraintTop_toTopOf="@+id/ivB2" />
<TextView
android:id="@+id/tvB3"
style="@android:style/TextAppearance.Medium"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginStart="10dp"
android:text="tvb3"
app:layout_constrainedWidth="true"
app:layout_constraintBottom_toTopOf="@+id/tvB4"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.5"
app:layout_constraintStart_toEndOf="@+id/ivB2"
app:layout_constraintTop_toTopOf="@+id/ivB4" />
<ImageView
android:id="@+id/ivB4"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="16dp"
app:layout_constraintStart_toStartOf="@+id/ivB2"
app:layout_constraintTop_toBottomOf="@+id/ivB2"
app:srcCompat="@mipmap/ic_launcher_round" />
<TextView
android:id="@+id/tvB4"
style="@android:style/TextAppearance.Medium"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginStart="10dp"
android:text="tvb4"
app:layout_constrainedWidth="true"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.5"
app:layout_constraintStart_toEndOf="@+id/ivB4"
app:layout_constraintTop_toBottomOf="@+id/tvB3" />
</androidx.constraintlayout.widget.ConstraintLayout>
</LinearLayout>
</androidx.cardview.widget.CardView>
如果你想得到类似的东西,请复制下面的代码 将textView置于左侧的关键是展开textView以匹配约束
<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"
style="@android:style/TextAppearance.Medium"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="tvB1"
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="0dp"
android:layout_height="wrap_content"
android:layout_marginStart="10dp"
android:text="tvb2"
app:layout_constrainedWidth="true"
app:layout_constraintBottom_toBottomOf="@+id/ivB2"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toEndOf="@+id/ivB2"
app:layout_constraintTop_toTopOf="@+id/ivB2" />
<TextView
android:id="@+id/tvB3"
style="@android:style/TextAppearance.Medium"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginStart="10dp"
android:text="tvb3"
app:layout_constrainedWidth="true"
app:layout_constraintBottom_toTopOf="@+id/tvB4"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.5"
app:layout_constraintStart_toEndOf="@+id/ivB2"
app:layout_constraintTop_toTopOf="@+id/ivB4" />
<ImageView
android:id="@+id/ivB4"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="16dp"
app:layout_constraintStart_toStartOf="@+id/ivB2"
app:layout_constraintTop_toBottomOf="@+id/ivB2"
app:srcCompat="@mipmap/ic_launcher_round" />
<TextView
android:id="@+id/tvB4"
style="@android:style/TextAppearance.Medium"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginStart="10dp"
android:text="tvb4"
app:layout_constrainedWidth="true"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.5"
app:layout_constraintStart_toEndOf="@+id/ivB4"
app:layout_constraintTop_toBottomOf="@+id/tvB3" />
</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>
但我认为在你的布局中,你添加了太多的限制。对于每个textView,您不必将约束设置为卡片视图的末尾。如果您只添加一个,它将自动启动。在这里,我只是将偏差设置为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>
但我认为在你的布局中,你添加了太多的限制。对于每个textView,您不必将约束设置为卡片视图的末尾。如果您只添加一个布局,它将自动启动。您可以添加整个布局吗?@I抱歉,我忘了这一点。我现在已经添加了。这个文本视图必须垂直扩展,否则你只想让它们像现在一样在高度上?@iknow我想让我的文本在左边,而不是中间。你能添加整个布局吗?@iknow抱歉,忘了这一点。我现在添加了它。这个文本视图必须垂直扩展,否则你只想让它们像现在一样在高度上?@iknow我想让我的文本在左边,而不是在中间,就像我想让我的文本在左边,而不是在中间现在如果这是你想要的结果?我想让我的文本在左边,而不是在中间现在,如果这是你想要的结果?