mini-reddit / app / src / main / res / layout / row_post.xml
row_post.xml
Raw
<?xml version="1.0" encoding="utf-8"?>
<androidx.cardview.widget.CardView
        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="wrap_content"
        android:focusable="true"
        android:clickable="true"
        android:layout_margin="8dp"
        android:background="?android:attr/selectableItemBackground">

    <androidx.constraintlayout.widget.ConstraintLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_gravity="center_horizontal"
        tools:context=".MainActivity">

        <TextView
            android:id="@+id/title"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:padding="6dp"
            android:textSize="16sp"
            app:layout_constraintBottom_toTopOf="@id/imageTextUnion"
            app:layout_constraintEnd_toEndOf="parent"
            app:layout_constraintStart_toStartOf="parent"
            app:layout_constraintTop_toTopOf="parent" />
        <!--Kind of a weird construction. The FrameLayout acts like -->
        <!-- a "union" that can contain either an ImageView or TextView-->
        <FrameLayout
            android:id="@+id/imageTextUnion"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            app:layout_constraintBottom_toTopOf="@+id/statsLayout"
            app:layout_constraintEnd_toEndOf="parent"
            app:layout_constraintStart_toStartOf="parent"
            app:layout_constraintTop_toBottomOf="@id/title">

            <ImageView
                android:id="@+id/image"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_gravity="center_horizontal|bottom"
                android:layout_margin="2dp"
                android:adjustViewBounds="true"
                android:scaleType="fitCenter" />

            <TextView
                android:id="@+id/selfText"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_gravity="center_horizontal|top"
                android:layout_margin="2dp"
                android:ellipsize="end"
                android:lines="6"
                android:padding="10dp"
                android:textSize="12sp" />
        </FrameLayout>

        <LinearLayout
            android:id="@+id/statsLayout"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            app:layout_constraintTop_toBottomOf="@+id/imageTextUnion">

            <LinearLayout
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_weight="2"
                android:orientation="horizontal">

                <ImageView
                    android:id="@+id/score_icon"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:layout_margin="12dp"
                    android:src="@drawable/ic_star_black_24dp" />

                <TextView
                    android:id="@+id/score"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:layout_margin="12dp"
                    android:gravity="center" />

            </LinearLayout>

            <LinearLayout
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_weight="2">

                <ImageView
                    android:id="@+id/commentsIcon"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:layout_margin="12dp"
                    android:src="@drawable/ic_comment_black_24dp" />

                <TextView
                    android:id="@+id/comments"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:layout_margin="12dp"
                    android:gravity="center" />
            </LinearLayout>

            <ImageView
                android:id="@+id/rowFav"
                android:layout_width="24dp"
                android:layout_height="wrap_content"
                android:layout_margin="12dp"
                android:layout_weight="1"
                android:src="@drawable/ic_favorite_border_black_24dp" />
        </LinearLayout>

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