#android #android-constraintlayout
#Android #android-constraintlayout
Вопрос:
Вот результат, который я хотел бы получить:
Я думаю, что приведенные изображения показали мою полную проблему, но взгляните на код моего вложенного макета. Вот результат, который я получаю в настоящее время:
<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>
Я не предоставляю полный код, потому что я пытаюсь, но этот сайт не позволяет мне это делать и показывает мне ошибку (похоже, что ваш пост в основном состоит из кода, пожалуйста, добавьте еще несколько деталей), для новых пользователей это как головная боль, когда они публикуют вопросы на этом сайте.
Комментарии:
1. можете ли вы показать нам, как это выглядит?
2. да, конечно, я все еще пытаюсь добавить изображения и завершить код
3. вы можете использовать относительный макет внутри ConstrainLayout..
4. Хорошо, это решает мою проблему?
5. @MansiJha ConstraintLayout — чрезвычайно мощный макет, и при его использовании вам редко нужно использовать вложенные представления. Итак, первое, что я бы сделал, это попытался избавиться от вложенного ConstraintLayout. Во-вторых, если бы вы могли прикрепить изображения того, что вы пытаетесь создать, и того, что вы на самом деле видите, это было бы чрезвычайно полезно.