Android ListView TextSize

my listview.xml

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout android:id="@+id/RelativeLayout01"
    android:layout_width="fill_parent" android:layout_height="fill_parent"
    xmlns:android="http://schemas.android.com/apk/res/android" xmlns:myapp="http://schemas.android.com/apk/res/zaid.quotes.dlama">
    <ListView android:id="@+id/ListView01" android:layout_width="wrap_content"
        android:layout_height="wrap_content" android:layout_alignParentTop="true"
        android:layout_marginBottom="50dp" android:paddingTop="50dp"></ListView>
    <Button android:layout_width="wrap_content"
        android:layout_height="wrap_content" android:id="@+id/Back"
        android:layout_alignParentBottom="true" android:text="Go Back"></Button>

    <LinearLayout android:layout_width="wrap_content"
        android:id="@+id/LinearLayout01" android:layout_height="wrap_content"
        android:layout_alignParentTop="true">
        <com.admob.android.ads.AdView android:id="@+id/ad"
            android:layout_width="fill_parent" android:layout_height="wrap_content"
            myapp:backgroundColor="#000000" myapp:primaryTextColor="#FFFFFF"
            myapp:secondaryTextColor="#CCCCCC" android:layout_alignParentTop="true" />
    </LinearLayout>


</RelativeLayout>

      

the current size of the text in the list is very large. and I can't figure out how to change the size of the text.

+2


a source to share


4 answers


What really matters here is the string View

you return to BaseAdapter

getView(..)

or CursorAdapter

newView(..)

.

You can copy simple_list_item_1.xml

or simple_list_item_2.xml

from Android sources and customize it according to your needs.
Let's say change
android:textAppearance="?android:attr/textAppearanceLarge"


for image android:textAppearance="?android:attr/textAppearanceMedium"

.



Another option is to change the appearance of the text in Adapter

by calling setTextAppearance(context, android.R.attr.textAppearanceMedium)

on TextView

.

+3


a source


I'm not sure if I'm getting what you want, but the listView has no text size, the items inside it are the ones that will determine their text size.



That is, if you add a text view to the list, determine the size of the text in the text element.

+2


a source


Yanchenko's answer works great if you rename your local simple_list_item_1.xml

MyActivity.java

:

ArrayAdapter<String> filesAdapter = new ArrayAdapter<String>(this, 
    R.layout.simplest_list_item_1, topFilesArray);
filesList.setDivider(null);

      

simplest_list_item_1.xml

:

<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:textSize="7pt"
    android:paddingLeft="6dip" />

      

layout_height="wrap_content"

used here for only 10 list items.

+1


a source


I think you have the wrong approach for using ListView. Use an adapter to feed the list to the view, and in the ListView layout file you are not defining strings, you are defining only the name of the list and the default text view that will be displayed when there are no items in the list. Then you define a separate XML file that will display each line. Then in the row layout, you can set the text size as you like.

Here is an example xml list (note the special id provided for view and text view, these AREs are required):

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:scrollbars="horizontal" android:orientation="vertical"
    android:layout_width="fill_parent" android:layout_height="fill_parent"
    android:paddingLeft="8dp" android:paddingRight="8dp">

    <ListView android:id="@+id/android:list" android:layout_width="fill_parent"
        android:layout_height="fill_parent" android:layout_weight="1"
        android:drawSelectorOnTop="false" />

    <TextView android:id="@+id/android:empty"
        android:layout_width="fill_parent" android:layout_height="fill_parent"
        android:text="No records found" />
</LinearLayout>

      

Then your line layout will be your unlisted file:

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout android:id="@+id/RelativeLayout01"
    android:layout_width="fill_parent" android:layout_height="fill_parent"
    xmlns:android="http://schemas.android.com/apk/res/android" xmlns:myapp="http://schemas.android.com/apk/res/zaid.quotes.dlama">
    <Button android:layout_width="wrap_content"
        android:layout_height="wrap_content" android:id="@+id/Back"
        android:layout_alignParentBottom="true" android:text="Go Back"></Button>

    <LinearLayout android:layout_width="wrap_content"
        android:id="@+id/LinearLayout01" android:layout_height="wrap_content"
        android:layout_alignParentTop="true">
        <com.admob.android.ads.AdView android:id="@+id/ad"
            android:layout_width="fill_parent" android:layout_height="wrap_content"
            myapp:backgroundColor="#000000" myapp:primaryTextColor="#FFFFFF"
            myapp:secondaryTextColor="#CCCCCC" android:layout_alignParentTop="true" />
    </LinearLayout>
</RelativeLayout>

      

And here is an example of the adapter getView () method in which you will set the row layout file:

public View getView(int position, View convertView, ViewGroup parent) {
        if (convertView == null) {
            LayoutInflater inflater = (LayoutInflater) context
                    .getSystemService(Context.LAYOUT_INFLATER_SERVICE);
            convertView = inflater.inflate(R.layout.row_layout, null);
        }
            //Now, assuming your adapter has the list of objects to be displayed in 'records':
            if(records != null) {
                    YourRecord r = records.get(position);
                    if(r != null) {
                            // Populate your views in your row.xml based on data from your record selected (r)
                    }
                    ...
             }

}

      

0


a source







All Articles