0

ImageView如图所示,我在 android studio 中并排放置的两个垂直线性布局之间添加时遇到问题。这里

<?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"
   xmlns:tools="http://schemas.android.com/tools"
   android:layout_width="match_parent"
   android:layout_height="match_parent"
   android:background="#FFFFFF"
   tools:context=".MainActivity">
   <androidx.constraintlayout.widget.ConstraintLayout
      android:layout_width="match_parent"
      android:layout_height="match_parent"
      android:alwaysDrawnWithCache="false"
      android:animateLayoutChanges="false"
      tools:visibility="visible" >
      <ImageView
         android:id="@+id/imageView11"
         android:layout_width="wrap_content"
         android:layout_height="wrap_content"
         android:layout_marginStart="80dp"
         android:layout_marginTop="73dp"
         android:layout_marginEnd="106dp"
         android:layout_marginBottom="304dp"
         app:layout_constraintBottom_toBottomOf="parent"
         app:layout_constraintEnd_toEndOf="parent"
         app:layout_constraintStart_toStartOf="parent"
         app:layout_constraintTop_toTopOf="parent"
         app:srcCompat="@drawable/download" />
   </androidx.constraintlayout.widget.ConstraintLayout>
   **<LinearLayout**
   android:layout_width="202dp"
   android:layout_height="598dp"
   android:background="#F4F6F2"
   android:backgroundTint="#F0F4EC"
   android:orientation="horizontal"
   tools:layout_editor_absoluteX="2dp"
   tools:layout_editor_absoluteY="4dp" />
   **<LinearLayout**
   android:layout_width="206dp"
   android:layout_height="601dp"
   android:background="#FEFEFF"
   android:backgroundTint="#2196F3"
   android:orientation="horizontal"
   tools:layout_editor_absoluteX="204dp"
   tools:layout_editor_absoluteY="1dp">
   </LinearLayout>
</androidx.constraintlayout.widget.ConstraintLayout>
4

2 回答 2

1

试试下面的代码,看看它是否有效:

   <?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"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent">

<LinearLayout
    android:id="@+id/linearLayout"
    android:layout_width="0dp"
    android:layout_height="0dp"
    android:background="#F4F6F2"
    android:backgroundTint="#F0F4EC"
    android:orientation="horizontal"
    app:layout_constraintBottom_toBottomOf="parent"
    app:layout_constraintEnd_toStartOf="@+id/linearLayout4"
    app:layout_constraintHorizontal_bias="0.5"
    app:layout_constraintStart_toStartOf="parent"
    app:layout_constraintTop_toTopOf="parent" />

<LinearLayout
    android:id="@+id/linearLayout4"
    android:layout_width="0dp"
    android:layout_height="0dp"
    android:background="#FEFEFF"
    android:backgroundTint="#2196F3"
    android:orientation="horizontal"
    app:layout_constraintBottom_toBottomOf="parent"
    app:layout_constraintEnd_toEndOf="parent"
    app:layout_constraintHorizontal_bias="0.5"
    app:layout_constraintStart_toEndOf="@+id/linearLayout"
    app:layout_constraintTop_toTopOf="parent">


</LinearLayout>

<androidx.constraintlayout.widget.ConstraintLayout
    android:id="@+id/constraintLayout"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:alwaysDrawnWithCache="false"
    android:animateLayoutChanges="false"
    app:layout_constraintBottom_toBottomOf="parent"
    app:layout_constraintEnd_toEndOf="parent"
    app:layout_constraintStart_toStartOf="parent"
    app:layout_constraintTop_toTopOf="parent"
    tools:visibility="visible">

    <ImageView
        android:id="@+id/imageView11"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        app:layout_constraintBottom_toBottomOf="parent"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toTopOf="parent"
        app:srcCompat="@drawable/download" />
</androidx.constraintlayout.widget.ConstraintLayout>
</androidx.constraintlayout.widget.ConstraintLayout>
于 2020-10-12T10:33:48.977 回答
0

不需要嵌套视图组,因为 constraintLayout 允许您创建具有平面视图层次结构的大型复杂布局。

<LinearLayout
    android:id="@+id/linearLayout"
    android:layout_width="0dp"
    android:layout_height="0dp"
    android:background="#F4F6F2"
    android:backgroundTint="#F0F4EC"
    android:orientation="horizontal"
    app:layout_constraintBottom_toBottomOf="parent"
    app:layout_constraintEnd_toStartOf="@+id/linearLayout4"
    app:layout_constraintStart_toStartOf="parent"
    app:layout_constraintTop_toTopOf="parent" />

<LinearLayout
    android:id="@+id/linearLayout4"
    android:layout_width="0dp"
    android:layout_height="0dp"
    android:background="#FEFEFF"
    android:backgroundTint="#2196F3"
    android:orientation="horizontal"
    app:layout_constraintBottom_toBottomOf="parent"
    app:layout_constraintEnd_toEndOf="parent"
    app:layout_constraintStart_toEndOf="@+id/linearLayout"
    app:layout_constraintTop_toTopOf="parent">

</LinearLayout>

<ImageView
    android:id="@+id/imageView11"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_marginTop="73dp"
    android:layout_marginBottom="304dp"
    app:layout_constraintBottom_toBottomOf="parent"
    app:layout_constraintEnd_toEndOf="parent"
    app:layout_constraintStart_toStartOf="parent"
    app:layout_constraintTop_toTopOf="parent"
    app:srcCompat="@drawable/badge_circle" />

上述更改按您的预期工作。

于 2020-10-12T11:01:50.223 回答