简体   繁体   中英

How to fix imageview positions but have variable textview above them in Android

I am currently working on an app and my layout is as follows:

  • I have a recyclerview holding all of my items, each item has a textview above an imageview. So the text view can expand up to 3 lines but only if needed. The recyclerview is using a gridlayout manager to display all of my items.

The problem is that currently when the text view expands to have more than 1 line it presses down the image instead of keeping it aligned with the other images in the row

What I currently have

What I want is to prevent the text view from pressing down on the image but instead build it's way up so that way the images stay normal and the text view will grow upwards like the image below.

What I want

Is there any way to achieve this? I would think it shouldn't be hard but I can't seem to find a way to accomplish this, or more likely, can't google the right terms to find the solution I'm looking for.

So I found an answer, I had to set two properties for my textview:

android:lines="3"
android:gravity="bottom"

so in the end each item had a layout below:

<RelativeLayout
  xmlns:android="http://schemas.android.com/apk/res/android"
  android:layout_height="wrap_content"
  android:layout_width="wrap_content"
  android:paddingStart="31dp"
  android:paddingEnd="32dp">

<TextView
    android:id="@+id/app_name"
    android:layout_width="@dimen/product_list_image_dimensions"
    android:layout_height="wrap_content"
    android:layout_centerHorizontal="true"
    android:text="@string/app_card_temp_name"
    android:textSize="@dimen/product_list_text_size"
    android:fontFamily="sans-serif-condensed"
    android:lines="3"
    android:textAlignment="center"
    android:textColor="@color/app_name_product_list_color"
    android:typeface="normal"
    android:gravity="bottom" />

<ImageView
    android:id="@+id/app_thumbnail"
    android:layout_width="@dimen/product_list_image_dimensions"
    android:layout_height="@dimen/product_list_image_dimensions"
    android:layout_below="@id/app_name"
    android:paddingTop="@dimen/product_list_text_bottom_padding"
    android:scaleType="centerCrop"
    android:layout_centerHorizontal="true" />

</RelativeLayout>

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM