机器人 - 获取ListView项的高度? [英] Android - Get ListView item height?

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

问题描述

有没有办法让ListViewItem的高度code,当在列表中没有实际的项目?

Is there a way to get ListViewItem height in code, when there is no actual items in list?

我的ListViewItem的布局:

My ListViewItem layout:

<LinearLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="?android:attr/listPreferredItemHeight">
...
</LinearLayout>  

我试图把它用吹气:

I have tried to get it using Inflater:

View convertView = LayoutInflater.from( this )
    .inflate( R.layout.mail_list_row, null );
int itemHeight = convertView.getHeight();

但它返回0;

But it's return 0;

谢谢!

推荐答案

在Android的看法是分配的宽度和高度,只有当它的渲染完成。所以,除非你列表ATLEAST渲染一旦你不会得到listItemHeight。解决你的问题可能是你设置一些最低高度列表项的,让你有ATLEAST东西,而不是硬编码的高度和宽度工作。

In android a view is assigned Width and Height only when its rendering is complete. So unless you list is rendered atleast once you won't get listItemHeight. Solution to your problem could be that you set some min Height of list Item so that you have atleast something to work with instead of Hard Coding height and width.

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

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