简体   繁体   中英

Bottom align a textview with an ImageView in a GridView

So far this is the result of my layout

布局

I am trying to put the textview at the bottom of my ImageView (not below it). The textview should BottomAlign with the ImageView.

The image of my ImageView is a square. If the content of the textview turns out to be longer that the width of my ImageView, the content should continues to the next line.

At the moment i don't care if the content of the ImageView does not scaled proportionally (ie gets stretched, etc).

This is the XML that i have:

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:orientation="vertical"
    android:padding="5dp">

    <ImageView
        android:id="@+id/iconItem"
        android:layout_width="80dp"
        android:layout_height="80dp"
        android:layout_alignBottom="@+id/textItem"
        android:scaleType="fitXY"
        android:padding="0dip"
        android:src="@drawable/shout_ic"/>
    <TextView
        android:id="@id/textItem"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:gravity="center"
        android:textAppearance="?android:attr/textAppearanceSmall"
        android:textSize="11sp"
        android:text="Motorcycles"
        android:textColor="#FFF"
        android:background="#8888"/>
</RelativeLayout>

How can i achieve the result i want?

EDIT 1:

I think i am making a progress... (but not exactly like what i have in mind

图像仍然太小

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:orientation="vertical"
    android:padding="5dp">

    <ImageView
        android:id="@+id/iconItem"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:scaleType="fitXY"
        android:padding="0dip"
        android:src="@drawable/thumbqoo_launcher_ic"/>
    <TextView
        android:id="@+id/textItem"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:gravity="center"
        android:layout_alignBottom="@+id/iconItem"
        android:textAppearance="?android:attr/textAppearanceSmall"
        android:textSize="11sp"
        android:text="Motorcycles"
        android:textColor="#FFF"
        android:background="#8888"/>
</RelativeLayout>

Change your parent layout to FrameLayout with orientation vertical like this

<?xml version="1.0" encoding="utf-8"?>
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="vertical"
android:padding="5dp" >

<ImageView
    android:id="@+id/iconItem"
    android:layout_width="80dp"
    android:layout_height="80dp"
    android:padding="0dip"
    android:scaleType="fitXY"
    android:src="@drawable/ic_launcher" />

<TextView
    android:id="@+id/textItem"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:background="#8888"
    android:gravity="center"
    android:layout_gravity="bottom"
    android:text="Motorcycles"
    android:textAppearance="?android:attr/textAppearanceSmall"
    android:textColor="#FFF"
    android:textSize="11sp" />

</FrameLayout>

remove this line android:layout_alignBottom="@+id/textItem" from your imageview and try adding line android:layout_alignBottom="@+id/iconItem" in your TextView

set width of ImageView to width of your row layout

    http://i.stack.imgur.com/HUY4o.png Check the sample image...
    <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
      android:id="@+id/album_item"
      android:layout_width="match_parent"
      android:layout_height="fill_parent"
      android:orientation="vertical" >

    <ImageView
       android:id="@+id/cover"
       android:layout_width="148dp"
       android:layout_height="148dp"
       android:src="@drawable/empty_photo" />

   <LinearLayout
     android:layout_width="match_parent"
     android:layout_height="wrap_content"
     android:layout_alignBottom="@+id/cover"
     android:background="#70000000"
     android:padding="6dp" >

     <TextView
        android:id="@+id/title"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:textColor="@color/white"
        android:textSize="12sp"
        android:textStyle="bold" />
      </LinearLayout>
    </RelativeLayout>
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:orientation="vertical"
    android:padding="5dp" >

    <ImageView
        android:id="@+id/iconItem"
        android:layout_width="80dp"
        android:layout_height="80dp"
        android:layout_alignBottom="@+id/textItem"
        android:padding="0dip"
        android:scaleType="fitXY"
        android:src="@drawable/shout_ic" />

    <TextView
        android:id="@id/textItem"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:background="#8888"
        android:gravity="center"
        android:text="Motorcycles"
        android:textAppearance="?android:attr/textAppearanceSmall"
        android:textColor="#FFF"
        android:textSize="11sp" android:layout_alignBottom="@id/iconItem"/>

</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