It looks like your code loads the TTF for every list item. That will
be very slow indeed. You should cache the font so that you load it
only once.

On Sun, Aug 17, 2008 at 10:55 PM, giolekva <[EMAIL PROTECTED]> wrote:
>
> Hi.
> I've wrote my own custom component UnicodeTextView which extends
> TextView. It supports fonts from assets and I'm using it in ListView.
> It takes too much time to render hole ListView. Do you know how I can
> improve it?
>
> Here is UnicodeTextView.java:
>
> package com.giolekva.android.widget;
>
> import java.util.Map;
>
> import com.giolekva.android.gcontacts.R;
>
> import android.content.Context;
> import android.content.Resources;
> import android.graphics.Typeface;
> import android.util.AttributeSet;
> import android.widget.TextView;
>
> public class UnicodeTextView extends TextView {
>        public UnicodeTextView(Context context, AttributeSet attrs, Map
> inflateParams, int defStyle) {
>                super(context, attrs, inflateParams, defStyle);
>
>                setFont(attrs);
>        }
>
>        public UnicodeTextView(Context context, AttributeSet attrs, Map
> inflateParams) {
>                super(context, attrs, inflateParams);
>
>                setFont(attrs);
>        }
>
>
>        public UnicodeTextView(Context context) {
>                super(context);
>        }
>
>        private void setFont(AttributeSet attrs) {
>                Resources.StyledAttributes a =
> getContext().obtainStyledAttributes(attrs,
> R.styleable.UnicodeTextView);
>                String fontName = 
> a.getString(R.styleable.UnicodeTextView_font);
>
>                if(fontName != null) {
>                        Typeface font = 
> Typeface.createFromAsset(getContext().getAssets(),
> "fonts/"+fontName);
>                        setTypeface(font);
>                }
>        }
> }
>
>
>
> and here is attrs.xml:
>
> <?xml version="1.0" encoding="UTF-8"?>
> <resources>
>        <declare-styleable name="UnicodeTextView">
>                <attr name="font" format="string" />
>        </declare-styleable>
> </resources>
>
>
> and declaration of one row of ListView:
>
> <?xml version="1.0" encoding="UTF-8"?>
> <com.giolekva.android.widget.UnicodeTextView xmlns:android="http://
> schemas.android.com/apk/res/android"
>        xmlns:gl="http://schemas.android.com/apk/res/
> com.giolekva.android.gcontacts"
>    android:id="@+id/contact_name"
>    android:layout_width="fill_parent"
>    android:layout_height="wrap_content"
>    android:textSize="@dimen/text_size"
>    android:textColor="@color/black"
>    android:paddingLeft="@dimen/padding"
>    android:paddingRight="@dimen/padding"
>    gl:font="sylfaen.ttf" />
>
> >
>



-- 
Romain Guy
www.curious-creature.org

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to android-developers@googlegroups.com
To unsubscribe from this group, send email to
[EMAIL PROTECTED]
Announcing the new M5 SDK!
http://android-developers.blogspot.com/2008/02/android-sdk-m5-rc14-now-available.html
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to