views:

546

answers:

3

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"&gt;
    <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 listview is large. and i cant seem to figure out how to change the text size.

A: 

I'm not sure if I'm getting what you want, but a listView doesn't have text size, the elements inside it are the ones that will define their text size.

That is, if you add a textview to the list, define the text size in the textView.

Maragues
A: 

What really matters here is the row View you return in BaseAdapter's getView(..) or CursorAdapter's newView(..).

You can copy simple_list_item_1.xml or simple_list_item_2.xml from Android sources and customize it to your needs.
Say, change
android:textAppearance="?android:attr/textAppearanceLarge"
to
android:textAppearance="?android:attr/textAppearanceMedium".

The other option is to change text appearance right in the Adapter by calling setTextAppearance(context, android.R.attr.textAppearanceMedium) on the TextView.

alex
A: 

I think you have the wrong approach to using a ListView. Use an adapter to feed the list to the view, and in the ListView layout file, you don't define the rows, you only define the listview itself and a default textview which will show when there are no items in the list. Then you define a separate xml file which will render each row. Then in this row layout you're free to set the text size as you wish.

Here's an example of the listview xml (notice the special id's given to the listview and textview, these 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 row layout would be your file without the listview:

<?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"&gt;
    <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's a sample of the adapter's getView() method where 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)
                    }
                    ...
             }

}
Ricardo Villamil