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

  • SEARCH
  • Home
  • 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 7607967
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T00:48:01+00:00 2026-05-31T00:48:01+00:00

I’m relative new to android programming and layouts, and got stuck on creating a

  • 0

I’m relative new to android programming and layouts, and got stuck on creating a custom listview with text and icons. I have checked and tried out several examples, and tried to make my own list view out of those. I’m now at such a point that I don’t know what I should do to get this to work like I want it to.

Here’s my current result (1st row), and the 2nd row is – my ugly MsPaint edition – of how I’d like it to be. Text which is cropped if it reaches the magnify-glass icon, with the 2 other icons after it.

Current and wanted state

I tried quite a few different layouts to accomplish this, and I’ve been told and read that I should use a relative layout, as those have a better performance and other thingies (which I can’t recall right now).

[Edit]Update and summarized issue: I have been puzzling a bit more, but I think that my real problem is the fact that the textview does not know in advance that I will put more icons on the right of the magnify glass. This means that it does not ‘reserve’ any space for those icons, and just takes all the available space, and only leaves some for the magnify icon.[/Edit]

I have 3 xml files which contain my layout. Here’s my first file, which is simply the layout I start the screen with:

    <?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    style="@style/LayoutWrap">

    <ListView
        android:id="@+id/my_listview"
        style="@style/List"/>
</LinearLayout>

The ‘xml-file’ of ‘my_listview’ (I know it’s a silly name :)):

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
 style="@style/myListItem"
 android:id="@+id/list">


    <TextView
    android:id="@+id/my_item_title"
    style="@style/myItemName"
    android:layout_alignParentLeft="true"
    android:layout_alignParentTop="true"
    android:layout_toLeftOf="@+id/my_item_detail"
    android:text="Name" />



    <ImageView
        android:id="@id/my_item_detail"
        style="@style/myImageItem"

        android:src="@drawable/ic_my_detail_unselected"
        android:contentDescription="Detail"
        android:layout_alignParentRight="true"
        android:layout_alignParentTop="true"
        android:layout_toLeftOf="@+id/my_item_delete"
    />


    <ImageView
        android:id="@id/my_item_delete"
        style="@style/myImageItem"

        android:src="@drawable/ic_my_delete_unselected"
        android:text="Delete my"
        android:layout_alignParentTop="true"
    />

        <ImageView
        android:id="@+id/my_item_copy"
        style="@style/myImageItem"

        android:src="@drawable/ic_my_update_unselected"
        android:text="Copy my"
        android:layout_alignParentTop="true"
        android:layout_toRightOf="@id/my_item_delete"
    />

</RelativeLayout>

In my ‘styles.xml’ are the styles defined, which don’t have any special properties. I think the only interesting thing is that I styled the text having a specific textSize (perhaps an ?android:LargeAppearance or so is better), and that I forced it on one line.

<?xml version="1.0" encoding="utf-8"?>
<resources>
        <style name="WrapBoth">
        <item name="android:layout_width">wrap_content</item>
        <item name="android:layout_height">wrap_content</item>
    </style>

    <style name="WrapHeight">
        <item name="android:layout_width">fill_parent</item>
        <item name="android:layout_height">wrap_content</item>
    </style>

        <style name="LayoutWrap">
        <item name="android:layout_width">fill_parent</item>
        <item name="android:layout_height">fill_parent</item>   
        <item name="android:orientation">vertical</item>        
    </style>

            <style name="List" parent="style/WrapHeight"/>

    <style name="myListItem">
        <item name="android:padding">5dp</item>
        <item name="android:layout_width">fill_parent</item>
        <item name="android:layout_height">?android:attr/listPreferredItemHeight</item>
    </style>

    <style name="myItemName" parent="style/WrapBoth">
        <item name="android:textSize">11sp</item>
        <item name="android:textStyle">bold</item>
        <item name="android:ellipsize">end</item>
        <item name="android:lines">1</item>
        <item name="android:scrollHorizontally">true</item>
    </style>

    <style name="myImageItem" parent="style/WrapBoth">

    </style>
</resources>

I’m already grateful for any help in advance! Meanwhile, I’ll work on my ‘buttonListeners’, I don’t expect those to be much of a trouble 🙂

  • 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-31T00:48:02+00:00Added an answer on May 31, 2026 at 12:48 am

    I’ve been able to solve this problem eventually, after I got more used to android and how the layouts work. And perhaps someone else might stumble upon the same issue and might get some useful info out of this.

    To solve this issue, I created a relativelayout which had the 3 images inside, and position the images as I’d like them to be. I gave my relativelayout the following properties:

    <RelativeLayout
            android:id="@id/options"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_alignParentRight="true"
            android:layout_centerVertical="true"
             >
    

    And the textview I wanted to stay on the left, I gave it the following properties:

    <TextView
        android:id="@+id/item_title"
        style="@style/ItemName"
        android:layout_alignParentLeft="true"
        android:layout_centerVertical="true"
        android:text="@string/dummy_title" 
        android:layout_toLeftOf="@+id/options"/>
    

    The styles I used, I kept those the same.
    Using this way, the layout knows what space should be reserved for the 3 images.

    It’s all a bit like in maths, stuff in brackets go first, and in android, stuff within layouts go first :).

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

Sidebar

Related Questions

I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I have a text area in my form which accepts all possible characters from
I have a reasonable size flat file database of text documents mostly saved in
I have a bunch of posts stored in text files formatted in yaml/textile (from
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I have just tried to save a simple *.rtf file with some websites and
For some reason, after submitting a string like this Jack’s Spindle from a text
I have a jquery bug and I've been looking for hours now, I can't
this is what i have right now Drawing an RSS feed into the php,
I've got a string that has curly quotes in it. I'd like to replace

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.