我在约束布局方面遇到问题,例如我正在使用两种布局,并且显示完美,但在运行时仅显示了第二种布局

时间:2019-04-23 09:57:09

标签: android android-constraintlayout

这是我想要得到的结果:

what i want

我认为给定的图像显示了我的完整问题,但请看一下我的嵌套布局的代码。这是我目前得到的结果:

what i am getting

<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"
android:orientation="horizontal"
tools:context=".Main2Activity">

<!--MY FIRST LAYOUT -->

<ImageView
    android:id="@+id/song_thumbnail"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_marginStart="8dp"
    android:layout_marginTop="8dp"
    android:layout_marginEnd="8dp"
    android:layout_marginBottom="8dp"
    app:layout_constraintBottom_toBottomOf="parent"
    app:layout_constraintEnd_toEndOf="parent"
    app:layout_constraintHorizontal_bias="0.0"
    app:layout_constraintStart_toStartOf="parent"
    app:layout_constraintTop_toTopOf="parent"
    app:layout_constraintVertical_bias="0.0"
    tools:srcCompat="@tools:sample/avatars" />

<TextView
    android:id="@+id/song_name"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_marginStart="8dp"
    android:layout_marginTop="8dp"
    android:layout_marginEnd="8dp"
    android:layout_marginBottom="8dp"
    android:textStyle="bold"
    android:textSize="15sp"
    android:singleLine="true"
    android:maxLength="20"
    android:text="TextView"
    app:layout_constraintBottom_toBottomOf="parent"
    app:layout_constraintEnd_toEndOf="parent"
    app:layout_constraintHorizontal_bias="0.055"
    app:layout_constraintStart_toEndOf="@+id/song_thumbnail"
    app:layout_constraintTop_toTopOf="parent"
    app:layout_constraintVertical_bias="0.079" />

<ImageButton
    android:id="@+id/more"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_marginStart="8dp"
    android:layout_marginTop="8dp"
    android:layout_marginEnd="8dp"
    android:layout_marginBottom="164dp"
    app:layout_constraintBottom_toBottomOf="parent"
    app:layout_constraintEnd_toEndOf="parent"
    app:layout_constraintHorizontal_bias="1.0"
    app:layout_constraintStart_toEndOf="@+id/song_name"
    app:layout_constraintTop_toTopOf="parent"
    app:layout_constraintVertical_bias="0.081"
    app:srcCompat="@drawable/recyclermore" />

<TextView
    android:id="@+id/song_artist"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_marginStart="8dp"
    android:layout_marginTop="8dp"
    android:layout_marginEnd="8dp"
    android:layout_marginBottom="8dp"
    android:singleLine="true"
    android:maxLength="15"
    android:textSize="10sp"
    android:text="TextView"
    app:layout_constraintBottom_toTopOf="@+id/more_buttons"
    app:layout_constraintEnd_toEndOf="parent"
    app:layout_constraintHorizontal_bias="0.055"
    app:layout_constraintStart_toEndOf="@+id/song_thumbnail"
    app:layout_constraintTop_toBottomOf="@+id/song_name"
    app:layout_constraintVertical_bias="0.413" />


<android.support.constraint.ConstraintLayout
    android:id="@+id/more_buttons"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:layout_marginStart="8dp"
    android:layout_marginTop="8dp"
    android:layout_marginEnd="8dp"
    android:layout_marginBottom="8dp"
    android:background="@drawable/round_corners"
    android:orientation="horizontal"
    app:layout_constraintBottom_toBottomOf="parent"
    app:layout_constraintEnd_toEndOf="parent"
    app:layout_constraintHorizontal_bias="1.0"
    app:layout_constraintStart_toStartOf="parent"
    app:layout_constraintTop_toBottomOf="@+id/song_thumbnail"
    app:layout_constraintVertical_bias="0.003">

    <ImageButton
        android:id="@+id/add_to"
        android:layout_width="wrap_content"
        android:layout_height="70dp"
        android:layout_marginStart="8dp"
        android:layout_marginEnd="8dp"
        android:background="#0000"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintHorizontal_bias="0.075"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toTopOf="parent"
        app:srcCompat="@drawable/recycleraddto" />

    <ImageButton
        android:id="@+id/delete"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_marginStart="8dp"
        android:layout_marginTop="8dp"
        android:layout_marginEnd="8dp"
        android:layout_marginBottom="8dp"
        android:background="#0000"
        app:layout_constraintBottom_toBottomOf="parent"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintHorizontal_bias="0.101"
        app:layout_constraintStart_toEndOf="@+id/add_to"
        app:layout_constraintTop_toTopOf="parent"
        app:layout_constraintVertical_bias="0.6"
        app:srcCompat="@drawable/recyclerdelete" />

    <ImageButton
        android:id="@+id/set_ringtone"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_marginStart="8dp"
        android:layout_marginTop="8dp"
        android:layout_marginEnd="8dp"
        android:background="#0000"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintHorizontal_bias="0.201"
        app:layout_constraintStart_toEndOf="@+id/delete"
        app:layout_constraintTop_toTopOf="parent"
        app:srcCompat="@drawable/recyclerringtone" />

    <ImageButton
        android:id="@+id/rename_title"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_marginStart="8dp"
        android:layout_marginTop="8dp"
        android:layout_marginEnd="8dp"
        android:background="#0000"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintHorizontal_bias="0.452"
        app:layout_constraintStart_toEndOf="@+id/set_ringtone"
        app:layout_constraintTop_toTopOf="parent"
        app:srcCompat="@drawable/recyclerrename" />
</android.support.constraint.ConstraintLayout>


</android.support.constraint.ConstraintLayout>

我没有提供完整的代码,因为我尝试但是此站点不允许我这样做并显示错误(您的帖子主要是代码,请添加一些详细信息),这对于新用户来说就像是头疼在此网站上发布问题。

0 个答案:

没有答案