How to decrease the size of the text in a Listview?

Asked

Viewed 1,687 times

2

I would like to know how to shorten or increase the text of ListView.
In the TextView there is the property android:textsize="15";, which property would be equivalent to textsize in the ListView?
I have a lot of information to put in it and so put one textsize smaller would solve my problem .

<ListView
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:id="@+id/ltsunidades"
    android:layout_below="@+id/txtselunidade"
    android:layout_alignParentLeft="true"
    android:layout_alignParentStart="true"
    android:layout_above="@+id/btnsairmenu"
    android:layout_alignRight="@+id/txtselunidade"
    android:layout_alignEnd="@+id/txtselunidade" 
    android:textsize=???
/>

The property above android:textsize does not work in the ListView.

  • 1

    Recommend revise your question, especially the first sentence that is confused. In addition, I recommend explaining the problem a little better and putting more tags so that people know what the question is about without having to enter it. I believe it’s about development Android, right? Put at least the tag #android in the question.

  • I reiterate what @Danieldutra said, your question is very confusing and in need of editing. If I can figure something out, you want to shorten the text of every item on the listview, right? If so, you have to add this "android:textsize" attribute to the <Textview> used in the layout of the items. Please confirm that this is your question that I try to explain better in a more detailed answer.

  • not I have a listview that will receive a lot of information... I just wish I could decrease the source of listview .. probably it has a default android size... I just wanted to decrease this font.. sorry if I couldn’t get through what I really want.. and that in editext or textview I can change the font size by increasing or decreasing it .. but in listview there is no such option.

  • 1

    From what I understand I think ListView is basically a list of TextView, this way you need to change the text size of the TextView used by ListView.

2 answers

2


Listview is a visual representation of data coming from a data source. Data is converted to Views using an Adapter.

I think you must be wearing one Arrayadapter, together with the View android.R.layout.simple_list_item_1

The data are presented with the "appearance" defined in this view

Nothing compels you to use that view, you can set another that will meet your needs.

Create a new layout with the name list_item_text.xml:

<?xml version="1.0" encoding="utf-8"?>
<TextView xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@android:id/text1"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:textAppearance="?android:attr/textAppearanceListItemSmall"
    android:gravity="center_vertical"
    android:paddingStart="?android:attr/listPreferredItemPaddingStart"
    android:paddingEnd="?android:attr/listPreferredItemPaddingEnd"
    android:minHeight="?android:attr/listPreferredItemHeightSmall" />

The above code is a copy of the file simple_list_item_1.xml, where is defined android.R.layout.simple_list_item_1.

Change it to your liking. Do not change the id, he needs to be @android:id/text1 so that it can be recognized by the Adapter.

For example, to change the textsize replace the line

android:textAppearance="?android:attr/textAppearanceListItemSmall"

for

android:textsize="15sp"

To use this new layout change the line:

setListAdapter(new ArrayAdapter<String>(this,android.R.layout.simple_list_item_1,oSeuArray));

for:

setListAdapter(new ArrayAdapter<String>(this, R.layout.list_item_text, oSeuArray));
  • 1

    I got it. thanks is exactly what I wanted.

0

In Listview there really is no such attribute, because Listview is actually (and obviously) a list of views and you will have to do the customizations you want directly in the views. Within each of your Listview views you should have a Textview to display the data, so you will add this attribute in Textview instead of using it in Listview.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.