How do I make two textviews in a ConstraintLayout in a CardView be flush?

时间:2018-06-04 17:07:32

标签: android android-layout

I'm a bit new to Android development, so I apologize if this question is simple. I have two textviews stacked vertically that I would like to get flush with each other. There's too much whitespace between the two elements:

Example layout

I have the following activity layout in which I've tried to make the TextViews flush by using a constraint view and setting the margin between the bottom and top to 0dp:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout 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:id="@+id/linearLayout"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical"
    tools:context=".PackageService">

    <android.support.v7.widget.CardView
        android:id="@+id/card_inventory"
        android:layout_width="match_parent"
        android:layout_height="101dp"
        android:layout_marginBottom="1dp"
        android:layout_marginTop="1dp">

        <android.support.constraint.ConstraintLayout
            android:layout_width="match_parent"
            android:layout_height="match_parent">

            <ImageView
                android:id="@+id/image_inventory"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_marginBottom="8dp"
                android:layout_marginEnd="8dp"
                android:layout_marginStart="8dp"
                android:layout_marginTop="8dp"
                android:src="@android:drawable/btn_star"
                app:layout_constraintBottom_toBottomOf="parent"
                app:layout_constraintEnd_toEndOf="parent"
                app:layout_constraintHorizontal_bias="0.048"
                app:layout_constraintStart_toStartOf="parent"
                app:layout_constraintTop_toTopOf="parent"
                app:layout_constraintVertical_bias="0.49" />

            <TextView
                android:id="@+id/text_inventory"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_marginBottom="0dp"
                android:layout_marginStart="32dp"
                android:text="Button Title"
                android:textAppearance="@android:style/TextAppearance.Material.Large"
                app:layout_constraintBottom_toTopOf="@id/text_last_scan"
                app:layout_constraintStart_toEndOf="@+id/image_inventory"
                app:layout_constraintTop_toTopOf="parent" />

            <TextView
                android:id="@+id/text_last_scan"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:text="Button Subtitle"
                app:layout_constraintBottom_toBottomOf="parent"
                app:layout_constraintStart_toStartOf="@+id/text_inventory"
                app:layout_constraintTop_toBottomOf="@+id/text_inventory" />
        </android.support.constraint.ConstraintLayout>
    </android.support.v7.widget.CardView>
</LinearLayout>

Any help would be appreciated.

0 个答案:

没有答案