设置ListView项的高度 [英] Set ListView item height

查看:129
本文介绍了设置ListView项的高度的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这应该是很容易的事,但看起来这是非常棘手的。 在我的code我有这样的ListView:

this should be a very easy thing to do, but it looks like it's very tricky. In my code I have this ListView:

<ListView android:id="@+id/sums_list" android:layout_width="fill_parent"
        android:layout_height="0dp" android:layout_weight="1" android:dividerHeight="0dp"></ListView>

这是填充使用该视图中的ArrayAdapter:

That is populated with an ArrayAdapter that uses this view:

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:cdpb="http://schemas.android.com/apk/res/ale.android.brainfitness"
    android:orientation="vertical" android:layout_width="fill_parent"
    android:layout_height="55dp">
...
</LinearLayout>

为什么不是项目55dp高?

Why isn't the item 55dp high?

谢谢大家

推荐答案

你是如何膨胀的看法?

How are you inflating the view?

如果您在设置父参数设置为null如下图所示,然后布局参数被忽略。

If you are setting 'parent' parameter to null like below, then layout parameters are ignored.

@Override
public View getView(int position, View convertView, ViewGroup parent) {
  ...
  View v = inflater.inflate(R.layout.filtered_trip_row, null);
  …

  return v;
}

过客父膨胀应该像您期望的。

Passing 'parent' to inflate should work as you expect.

@Override
public View getView(int position, View convertView, ViewGroup parent) {
  ...
  View v = inflater.inflate(R.layout.filtered_trip_row, parent);
  …

  return v;
}

这说明它的细节: LayoutInflater 的决策意识

This explains it in detail: Making sense of LayoutInflater

要避免让 UnsupportedOperationException异常,您可以添加作为输入参数的充气。例如:

To avoid getting UnsupportedOperationException, you can add false as an input parameter to the inflator. Example:

inflater.inflate(R.layout.filtered_trip_row, parent, false)

这篇关于设置ListView项的高度的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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