How to decrease the size of text in a ListView?

1

I would like to know how to decrease or increase the text of ListView . In TextView , android:textsize="15"; exists, what would be the equivalent property to textsize in ListView ? I have a lot of information to put into it and so putting a textsize minor 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 above property android:textsize does not work in ListView .

    
asked by anonymous 26.04.2016 / 15:07

2 answers

1

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

I think you should be using an ArrayAdapter , along with View android.R.layout.simple_list_item_1

The data is presented with the "look and feel" defined in this view

Nothing obliges you to use this view , you can define another that meets 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 code above is a copy of the simple_list_item_1.xml file, where android.R.layout.simple_list_item_1 is set.

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

For example, to change textsize replace the

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

by

android:textsize="15sp"

To use this new layout change the line:

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

To:

setListAdapter(new ArrayAdapter<String>(this, R.layout.list_item_text, oSeuArray));
    
27.04.2016 / 17:37
0

In the ListView there really is no such attribute, because the ListView is actually (and obviously) a list of views and you will have to make the customizations that you want directly in the views. Within each of the views of your ListView must have a TextView to display the data, then you will add this attribute in the TextView instead of using it in the ListView.

    
27.04.2016 / 15:43