如何设置自定义列表视图项的身高......? [英] How to set custom list view item's height...?

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

问题描述

我有一个包含两个文本视图和按钮自定义列表视图。
我已经定制的按钮样式。
在列表视图中的每一行是不适合正常显示我的按钮。
我想改变列表项的高度。
我怎样才能做到这一点..?

I have a custom list view which contains two text views and on button. I have customized the button style. In the list view each row is not fit to show my button properly. I want to change the list item's height. How can i do that..?

这是我的列表视图。

<ListView android:layout_width="fill_parent"
        android:scrollbars="none" android:footerDividersEnabled="false"
        android:minHeight="50dp"
        android:listSelector="#00000000" android:dividerHeight="0px"
        android:divider="#00000000" android:layout_height="fill_parent"
        android:layout_marginLeft="5dp" android:layout_marginTop="5dp"
        android:layout_marginRight="5dp" android:id="@+id/list_view"
        android:cacheColorHint="#00000000" android:background="#00000000" />

我的自定义视图XML

my custom view xml

<?xml version="1.0" encoding="UTF-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:orientation="horizontal" android:layout_width="fill_parent"
    android:layout_height="wrap_content">

    <TextView android:layout_width="150dp"
        android:layout_height="wrap_content" 
        android:textColor="#808080" android:text="Subtitle 2" android:id="@+id/text1" 
        android:layout_marginLeft="5dp"
        android:singleLine="true"/>

    <TextView android:layout_width="60dp"
        android:layout_height="wrap_content" 
        android:textColor="#808080" android:text="$ 00.00" android:id="@+id/text2" 
        android:singleLine="true"/>

    <Button android:layout_width="80dp" android:layout_height="25dp"
        android:background="@drawable/type10_subbg" android:text="Add"
        android:textSize="20dp" android:textStyle="bold" android:textColor="#153E7E"
        android:id="@+id/add" />
</LinearLayout>   

下面是我的getView。

Here is my getView.

@SuppressWarnings("unchecked")
@Override
public View getView(int position, View convertView, ViewGroup parent) {
    ViewHolder holder;
    pos = position;
    holder = new ViewHolder();
    convertView = inflater.inflate(R.layout.type10_sub, null);          
    holder.text1 = (TextView) convertView.findViewById(R.id.text1);
    holder.text2 = (TextView) convertView.findViewById(R.id.text2);
    holder.add = (Button) convertView.findViewById(R.id.add);
    holder.add.setTag(String.valueOf(position));
    holder.add.setOnClickListener(new OnClickListener() {           
        @Override
        public void onClick(View v) {
            Button b = (Button)v;
            int tag = Integer.valueOf((String)b.getTag());
            System.out.println("Added at "+tag);
            System.out.println("Data = "+((HashMap<String,Object>)list.get(tag)).get("text1").toString());
            System.out.println("Price = "+((HashMap<String,Object>)list.get(tag)).get("text2").toString());             }
    });         holder.text1.setText(((HashMap<String,Object>)list.get(position)).get("text1").toString());
    holder.text2.setText(((HashMap<String,Object>)list.get(position)).get("text2").toString());
    convertView.setTag(holder);
    return convertView;
}

在此先感谢....!

Thanks in advance....!

推荐答案

convertedview.setlayoutparams(新Listview.setlayoutparams(宽度,高度));

先放的LinearLayout 而不是的ListView

,然后编辑到的ListView 否则将无法正常工作。这是招。

and then edit that to ListView otherwise it will not work. This is the trick.

这篇关于如何设置自定义列表视图项的身高......?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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