Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 680795
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 14, 20262026-05-14T01:24:43+00:00 2026-05-14T01:24:43+00:00

I am using a list view in Android 1.5 to show a list of

  • 0

I am using a list view in Android 1.5 to show a list of images and text next to the image. I am trying to vertically center the text but the text is at the top of the row instead of centered. Below is my layout:

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/row"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:padding="10dip">

    <ImageView android:id="@+id/item_image" android:layout_width="wrap_content" 
        android:layout_height="wrap_content"  android:paddingRight="10dip" 
        android:src="@drawable/default_image" android:layout_alignParentLeft="true"
        android:layout_alignParentTop="true"
        android:layout_alignParentBottom="true"
        android:layout_centerVertical="true"
        android:gravity="center_vertical"/>

    <TextView android:id="@+id/item_title" 
        android:layout_width="wrap_content" android:layout_height="wrap_content" 
        android:layout_toRightOf="@id/item_image" 
        android:layout_alignParentTop="true"
        android:layout_alignParentBottom="true"
        android:layout_centerVertical="true"
        android:gravity="center_vertical"
        />

</RelativeLayout>

It seems strange that I need to set alignParentTop=”true” when I’m trying to vertically center the text, but if I don’t the text does not even show up. What am I doing wrong?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-14T01:24:44+00:00Added an answer on May 14, 2026 at 1:24 am

    EDIT following the comments:

    It turns out making this work with RelativeLayout isn’t easy. At the bottom of the answer I’ve included a RelativeLayout that gives the effect wanted, but only until it’s included in a ListView. After that, the same problems as described in the question occurred. This was fixed by instead using LinearLayout(s).

    <?xml version="1.0" encoding="utf-8"?>
    <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:paddingLeft="10dp"
        android:orientation="horizontal">
    
        <ImageView android:id="@+id/pickImageImage" 
            android:layout_width="100dp"
            android:layout_height="80dp"
            android:background="@drawable/icon"
            android:scaleType="fitXY"
            android:layout_marginRight="10dp"/>
    
        <TextView android:id="@+id/pickImageText" 
            android:layout_height="fill_parent"
            android:layout_width="fill_parent"
            android:gravity="left|center_vertical"
            android:text="I'm the text"/>
    
    </LinearLayout>
    

    If you want to have two text boxes, you can nest a second orientation="vertical" and LinearLayout after the ImageView and then put the text boxes in there.

    This works, but I have to admit I don’t know why the RelativeLayouts didn’t. For example, this blog post by Romain Guy specifically says that the RelativeLayout should. When I tried it, I never got it to quite work; admittedly I didn’t do it exactly as he did, but my only changes were with some attributes of the TextViews, which shouldn’t have made that much of a difference.


    Here’s the original answer:

    I think you’re confusing Android with all those somewhat contradictory instructions in RelativeLayout. I reformatted your thing to this:

    <?xml version="1.0" encoding="utf-8"?>
    <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
        android:id="@+id/row"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:padding="10dip">
    
        <ImageView android:id="@+id/item_image"
            android:layout_width="wrap_content" 
            android:layout_height="wrap_content"
            android:paddingRight="10dip" 
            android:src="@drawable/icon"
            android:layout_alignParentLeft="true"
            android:layout_alignParentTop="true"/>
    
        <TextView android:id="@+id/item_title" 
            android:layout_width="wrap_content"
            android:layout_height="wrap_content" 
            android:layout_toRightOf="@id/item_image" 
            android:layout_centerVertical="true"
            android:text="Blah!"/>
    
    </RelativeLayout>
    

    And that works fine. I removed many of your redundant android:layout_alignParentxxx because they weren’t necessary. This view now comes up with the picture in the top left corner and the text vertically centered next to it. If you want the picture vertically centered as well, then you can’t have the RelativeLayout be on android:layout_height=”wrap_content” because it’s trying to make itself no taller than the height of the picture. You’d have to specify a height, e.g. 80dp, and then set the ImageView to a fixed height like 60dp with android:scaleType=”fitXY” to make it scale down to fit properly.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I wanted to generate a list view using below code. But after running this
I'm trying to create a page by using view 2. This page list all
How to differentiate between different items in list view, using ListActivity(Android) . For example
I'm using a ListView that is setup like this: <ListView android:id=@android:id/list android:layout_width=fill_parent android:layout_height=fill_parent android:longClickable=false
I have created navigaton view using Sencha touch 2. Navigation view has list component
In my Android application, I have a simple list view with adapter. There's a
UPDATED: Hi i'm using spinner within AlertDialog.Builder to show the list of options to
I'm trying to make a LazyList EndlessList but using a sectioned adapter...The sections will
I've got a ListView with a 'show next results' button. The list is filled
How to create a simple list view using only array adapter and getview. Without

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.