looking for some solutions? You are welcome.

SOLVED: Android TextView align text vertically within the bounding box

Code Lover:

Note: I am troubling aligning text within the bounding box not within the parent view.

This happens when I apply background color to the TextView so I can reduce one parent layout just to add background color

enter image description here

XML File

<?xml version="1.0" encoding="utf-8"?>
<android.support.v7.widget.CardView xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:id="@+id/item_card"
    style="@style/CardViewTheme"
    android:layout_width="96dp"
    android:layout_height="96dp"
    app:layout_constraintBottom_toBottomOf="parent"
    app:layout_constraintEnd_toEndOf="parent"
    app:layout_constraintStart_toStartOf="parent"
    app:layout_constraintTop_toTopOf="parent">

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

        <ImageView
            android:id="@+id/item_icon"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_marginTop="10dp"
            android:layout_marginBottom="8dp"
            android:src="@drawable/ic_item_icon"
            app:layout_constraintBottom_toTopOf="@+id/item_name"
            app:layout_constraintEnd_toEndOf="parent"
            app:layout_constraintHorizontal_bias="0.5"
            app:layout_constraintStart_toStartOf="parent"
            app:layout_constraintTop_toTopOf="parent"
            app:layout_constraintVertical_chainStyle="spread_inside" />

        <TextView
            android:id="@+id/item_name"
            style="@style/BodyMenuText"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_marginBottom="8dp"
            android:gravity="center"
            android:text="Flat Tire"
            android:textAlignment="center"
            app:layout_constraintBottom_toTopOf="@+id/item_price"
            app:layout_constraintEnd_toEndOf="parent"
            app:layout_constraintHorizontal_bias="0.5"
            app:layout_constraintStart_toStartOf="parent"
            app:layout_constraintTop_toBottomOf="@+id/item_icon" />

        <TextView
            android:id="@+id/item_price"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:background="@color/colorDarkestGray"
            android:gravity="center"
            android:padding="4dp"
            android:text="USD 40"
            android:textSize="@dimen/app_caption_text"
            app:layout_constraintBottom_toBottomOf="parent"
            app:layout_constraintEnd_toEndOf="parent"
            app:layout_constraintHorizontal_bias="0.5"
            app:layout_constraintStart_toStartOf="parent"
            app:layout_constraintTop_toBottomOf="@+id/item_name" />

    </android.support.constraint.ConstraintLayout>

</android.support.v7.widget.CardView>



Posted in S.E.F
via StackOverflow & StackExchange Atomic Web Robots
Share:

No comments:

Recent