Не включайте drawableLeft при выравнивании элементов - PullRequest
0 голосов
/ 28 мая 2020

У меня есть два textViews, один под другим, например:

enter image description here

и вот как это выглядит из кода

   <TextView
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:drawableStart="@drawable/ic_some_sign"
        android:text="Some text in here" />

    <TextView
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:text="June 2015" />

Я хочу переместить красный кружок из-под выравнивания, чтобы два вида были выровнены только по тексту.

, чтобы это выглядело так:

enter image description here

Я могу добавить ImageVIew, и это поможет, но мне любопытно, есть ли другой способ.

Спасибо

Ответы [ 2 ]

0 голосов
/ 28 мая 2020

Вы можете использовать две линейные раскладки. Один для красного круга и текста. Другой для двух видов текста.

 <RelativeLayout
    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:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:orientation="horizontal"
        >

        <ImageView
            android:layout_width="20dp"
            android:layout_height="20dp"
            app:srcCompat="@drawable/ic_red_circle"
            />

        <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:orientation="vertical"
            >

            <TextView
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:text="Some text in here" />

            <TextView
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:text="June 2015" />

        </LinearLayout>

    </LinearLayout>

   </RelativeLayout>
0 голосов
/ 28 мая 2020

Используйте view или imageView, например форму красного круга и два textView, и поместите их в constraintLayout, как это.

<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    xmlns:app="http://schemas.android.com/apk/res-auto">

    <ImageView
        android:layout_width="20dp"
        android:layout_height="20dp"
        android:layout_margin="8dp"
        android:id="@+id/imageRedCircle"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toTopOf="parent" />

    <TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        app:layout_constraintStart_toEndOf="@+id/imageRedCircle"
        app:layout_constraintTop_toTopOf="@id/imageRedCircle"
        android:text="Some text in here"
        android:id="@+id/textViewSomeText"
        app:layout_constraintBottom_toBottomOf="@id/imageRedCircle"/>

    <TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="June 2015"
        app:layout_constraintStart_toStartOf="@id/textViewSomeText"
        app:layout_constraintTop_toBottomOf="@id/textViewSomeText"/>

</androidx.constraintlayout.widget.ConstraintLayout>
...