如何设置在Android的使用XML列表视图项TEXTSIZE? [英] How to set the textsize in Listview items in android using xml?

查看:162
本文介绍了如何设置在Android的使用XML列表视图项TEXTSIZE?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是可能的设置或更改项目的文本大小在列表视图

如果这样可能解释的可能性。

if so possible explain the possibilities.

推荐答案

list_screen_layout.xml

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent" >

<ListView
    android:id="@+id/listScreen"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:layout_alignParentLeft="true" >
</ListView>

ListScreen活性的研究

    public class ListSreen extends FragmentActivity {
    private ListView list;
    private String[] strData = new String[('Z' - 'A') + 1];;
    private TestAdapter adapterData;
    private int i = 0;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);

        try {
            setContentView(R.layout.list_screen_layout);
            list = (ListView) findViewById(R.id.listScreen);
            for (char c = 'A'; c <= 'Z'; c++) {
                strData[i++] = String.valueOf(c);
            }
            adapterData = new TestAdapter(strData, this);
            list.setAdapter(adapterData);

        } catch (Exception e) {
            e.printStackTrace();
        }

    }
}

TestAdapter

    public class TestAdapter extends BaseAdapter {
    private int size = 0;

    public TestAdapter(String[] strData, Context cntx) {
        this.strData = strData;
        this.cntx = cntx;
        if (this.strData != null)
            size = this.strData.length;
    }

    String[] strData;
    private Context cntx;

    @Override
    public int getCount() {
        // TODO Auto-generated method stub
        return size;
    }

    @Override
    public String getItem(int position) {
        // TODO Auto-generated method stub
        return this.strData[position];
    }

    @Override
    public long getItemId(int position) {
        // TODO Auto-generated method stub
        return position;
    }

    class Holder {
        TextView lbl;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        Holder holder;
        if (convertView == null) {
            holder = new Holder();
            convertView = LayoutInflater.from(cntx).inflate(
                    R.layout.list_row_item, null);
            holder.lbl = (TextView) convertView.findViewById(R.id.lbl_text);
            convertView.setTag(holder);
        } else {
            holder = (Holder) convertView.getTag();
        }
        /*
         * textview style and all here can also b add here
         */
        holder.lbl.setText(this.strData[position]);

        return convertView;
    }

}

这篇关于如何设置在Android的使用XML列表视图项TEXTSIZE?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆