Android 如何更改ListView的字体大小和对齐方式

Android 如何更改ListView的字体大小和对齐方式,android,android-listview,parse-platform,Android,Android Listview,Parse Platform,我有一个列表视图,其中填充了Parse.com数据库中的值,然后显示它们。我看到了普通列表的字体和大小是如何改变的,但它们对我的列表不起作用。这是我的全部代码 public class OfferPage extends Activity { String obj; ProgressDialog mProgressDialog; @Override protected void onCreate(Bundle savedInstanceState) {

我有一个列表视图,其中填充了Parse.com数据库中的值,然后显示它们。我看到了普通列表的字体和大小是如何改变的,但它们对我的列表不起作用。这是我的全部代码

public class OfferPage extends Activity {
    String obj;
    ProgressDialog mProgressDialog;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_offer_page);

        Intent i = getIntent();
        obj = i.getStringExtra("RestName");
        populateList(obj, "Restraunt");
    }

    private void populateList(final String Value, final String Key) {
        ParseQueryAdapter.QueryFactory<ParseObject> factory = new ParseQueryAdapter.QueryFactory<ParseObject>() {

            @Override
            @SuppressWarnings({ "unchecked", "rawtypes" })
            public ParseQuery create() {
                ParseQuery query = new ParseQuery("Offers");
                query.whereEqualTo(Key, Value);
                return query;
            }
        };
        ParseQueryAdapter<ParseObject> adapter = new ParseQueryAdapter<ParseObject>(
                this, factory);
        adapter.setTextKey("Offer");
        adapter.addOnQueryLoadListener(new OnQueryLoadListener<ParseObject>() {

            @Override
            public void onLoading() {
                mProgressDialog = new ProgressDialog(OfferPage.this);
                mProgressDialog.setTitle("Searching for Offers");
                mProgressDialog.setMessage("Loading...");
                mProgressDialog.setIndeterminate(false);
                mProgressDialog.show();
            }

            @Override
            public void onLoaded(List<ParseObject> objects, Exception e) {
                mProgressDialog.dismiss();
            }
        });

        final ListView listView = (ListView) findViewById(R.id.offerList);
        listView.setAdapter(adapter);
    }

    @Override
    public boolean onCreateOptionsMenu(Menu menu) {
        // Inflate the menu; this adds items to the action bar if it is present.
        getMenuInflater().inflate(R.menu.offer_page, menu);
        return true;
    }

    @Override
    public boolean onOptionsItemSelected(MenuItem item) {
        // Handle action bar item clicks here. The action bar will
        // automatically handle clicks on the Home/Up button, so long
        // as you specify a parent activity in AndroidManifest.xml.
        int id = item.getItemId();
        if (id == R.id.action_settings) {
            return true;
        }
        return super.onOptionsItemSelected(item);
    }
}
公共类OfferPage扩展活动{
字符串对象;
进程对话框;
@凌驾
创建时受保护的void(Bundle savedInstanceState){
super.onCreate(savedInstanceState);
setContentView(R.layout.activity\u offer\u页面);
Intent i=getIntent();
obj=i.getStringExtra(“RestName”);
大众主义者(obj,Restrant);
}
私有void populateList(最终字符串值、最终字符串键){
ParseQueryAdapter.QueryFactory=新建ParseQueryAdapter.QueryFactory(){
@凌驾
@SuppressWarnings({“unchecked”,“rawtypes”})
公共ParseQuery创建(){
ParseQuery=新的ParseQuery(“报价”);
查询。whereEqualTo(键,值);
返回查询;
}
};
ParseQueryAdapter=新的ParseQueryAdapter(
这家工厂);
adapter.setTextKey(“要约”);
addOnQueryLoadListener(新的OnQueryLoadListener(){
@凌驾
公共无效加载(){
mProgressDialog=新建进度对话框(OfferPage.this);
mProgressDialog.setTitle(“搜索报价”);
设置消息(“加载…”);
mProgressDialog.setUndeterminate(false);
mProgressDialog.show();
}
@凌驾
已加载公共void(列出对象,异常e){
mProgressDialog.disclose();
}
});
最终ListView ListView=(ListView)findViewById(R.id.offerList);
setAdapter(适配器);
}
@凌驾
公共布尔onCreateOptions菜单(菜单){
//为菜单充气;这会将项目添加到操作栏(如果存在)。
getMenuInflater().充气(右菜单提供页面,菜单);
返回true;
}
@凌驾
公共布尔值onOptionsItemSelected(菜单项项){
//处理操作栏项目单击此处。操作栏将
//自动处理Home/Up按钮上的点击,只要
//在AndroidManifest.xml中指定父活动时。
int id=item.getItemId();
if(id==R.id.action\u设置){
返回true;
}
返回super.onOptionsItemSelected(项目);
}
}

我似乎不知道该怎么办,读一些其他问题的建议,但它们不起作用

也许这会有帮助,这是一个可扩展的列表

public class ExpandableListAdapter extends BaseExpandableListAdapter {

private Context _context;
private List<String> _listDataHeader; // header titles
// child data in format of header title, child title
private HashMap<String, List<String>> _listDataChild;

public ExpandableListAdapter(Context context, List<String> listDataHeader,
        HashMap<String, List<String>> listChildData) {
    this._context = context;
    this._listDataHeader = listDataHeader;
    this._listDataChild = listChildData;
}

@Override
public Object getChild(int groupPosition, int childPosititon) {
    return this._listDataChild.get(this._listDataHeader.get(groupPosition)).get(childPosititon);
}

@Override
public long getChildId(int groupPosition, int childPosition) {
    return childPosition;
}

@Override
public View getChildView(int groupPosition, final int childPosition, boolean isLastChild, View convertView,
        ViewGroup parent) {

    final String childText = (String) getChild(groupPosition, childPosition);

    if (convertView == null) {
        LayoutInflater infalInflater = (LayoutInflater) this._context
                .getSystemService(Context.LAYOUT_INFLATER_SERVICE);
        convertView = infalInflater.inflate(R.layout.xx_listview_child, null);
    }

    TextView txtListChild = (TextView) convertView.findViewById(R.id.child);

    txtListChild.setText(childText);
    return convertView;
}

@Override
public int getChildrenCount(int groupPosition) {
    return this._listDataChild.get(this._listDataHeader.get(groupPosition)).size();
}

@Override
public Object getGroup(int groupPosition) {
    return this._listDataHeader.get(groupPosition);
}

@Override
public int getGroupCount() {
    return this._listDataHeader.size();
}

@Override
public long getGroupId(int groupPosition) {
    return groupPosition;
}

@Override
public View getGroupView(int groupPosition, boolean isExpanded, View convertView, ViewGroup parent) {
    String headerTitle = (String) getGroup(groupPosition);

    if (convertView == null) {
        LayoutInflater infalInflater = (LayoutInflater) this._context
                .getSystemService(Context.LAYOUT_INFLATER_SERVICE);
        convertView = infalInflater.inflate(R.layout.xx_listview_item, null);
    }

    TextView lblListHeader = (TextView) convertView.findViewById(R.id.myitem);
    lblListHeader.setTypeface(null, Typeface.BOLD);
    lblListHeader.setText(headerTitle);

    return convertView;
}

@Override
public boolean hasStableIds() {
    return false;
}

@Override
public boolean isChildSelectable(int groupPosition, int childPosition) {
    return true;
}

public boolean shouldExpand(boolean expand) {
    return expand;
}

}
公共类ExpandableListAdapter扩展了BaseExpandableListAdapter{
私人语境(private Context)(私人语境);;
私有列表_listDataHeader;//头标题
//标题标题、子标题格式的子数据
私有HashMap_listDataChild;
公共ExpandableListAdapter(上下文、列表listDataHeader、,
HashMap listChildData){
这._context=context;
这。_listDataHeader=listDataHeader;
这。_listDataChild=listChildData;
}
@凌驾
公共对象getChild(int-groupPosition、int-ChildPosition){
返回此。_listDataChild.get(此。_listDataHeader.get(groupPosition)).get(childpositionon);
}
@凌驾
公共长getChildId(int-groupPosition,int-childPosition){
返回子位置;
}
@凌驾
公共视图getChildView(int groupPosition,final int childPosition,boolean isLastChild,View convertView,
视图组(父级){
最终字符串childText=(字符串)getChild(groupPosition,childPosition);
if(convertView==null){
LayoutInflater infalInflater=(LayoutInflater)this.\u上下文
.getSystemService(上下文布局\充气机\服务);
convertView=infalInflater.充气(R.layout.xx\u listview\u child,null);
}
TextView txtListChild=(TextView)convertView.findViewById(R.id.child);
setText(childText);
返回视图;
}
@凌驾
公共整数getChildrenCount(整数组位置){
返回此。_listDataChild.get(此。_listDataHeader.get(groupPosition)).size();
}
@凌驾
公共对象getGroup(int-groupPosition){
返回此。\u listDataHeader.get(groupPosition);
}
@凌驾
public int getGroupCount(){
返回此值。_listDataHeader.size();
}
@凌驾
公共长getGroupId(int-groupPosition){
返回组位置;
}
@凌驾
公共视图getGroupView(int groupPosition、布尔isExpanded、视图convertView、视图组父级){
字符串头文件=(字符串)getGroup(groupPosition);
if(convertView==null){
LayoutInflater infalInflater=(LayoutInflater)this.\u上下文
.getSystemService(上下文布局\充气机\服务);
convertView=infalInflater.充气(R.layout.xx\u列表视图\u项,空);
}
TextView lblListHeader=(TextView)convertView.findViewById(R.id.myitem);
lblListHeader.setTypeface(null,Typeface.BOLD);
lblListHeader.setText(标题);
返回视图;
}
@凌驾
公共布尔表ID(){
返回false;
}
@凌驾
公共布尔值isChildSelectable(int-groupPosition,int-childPosition){
返回true;
}
公共布尔值shouldExpand(布尔值扩展){
回报扩大;
}
}
xx_listview_child.xml

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="55dip"
    android:orientation="vertical" >

    <TextView
        android:id="@+id/child"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:textSize="17sp"
        android:paddingTop="5dp"
        android:paddingBottom="5dp"
        android:paddingLeft="?android:attr/expandableListPreferredChildPaddingLeft"
        android:textColor="#FFFFFF" />

</LinearLayout>

xx_listview_intem.xml

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:orientation="vertical"
    android:padding="8dp" >

    <TextView
        android:id="@+id/myitem"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:textSize="17sp"
        android:textColor="#33b5e5" />

</LinearLayout>


您必须创建自定义列表视图。这里有一个很好的例子:我仍然不知道如何在我的案例中使用它。你有没有更好解释的示例代码