android-如何动态获取列表视图的宽度和高度视图、宽度、高度、动态

2023-09-06 17:24:40 作者:‘媳婦’咱不鬧

在我的应用程序,我想用适配器显示列表视图。但我想获取列表视图当前的高度和宽度(生成使用适配器列表后的意思)。如何得到它。任何人可以帮助我。

In my application i want display list view using adapter. But i want get the current height and width of the list view (means after generating the list using adapter). how to get it. can anybody help me.

感谢

推荐答案

使用的getWidth()的getHeight() ListView控件的方法 onWindowFocusChanged 获得的宽度和高度。

Use getWidth() and getHeight() method of ListView in onWindowFocusChanged to get the width and height.

@Override
public void onWindowFocusChanged(boolean hasFocus) {
    super.onWindowFocusChanged(hasFocus);


    System.out.println("Width:" + listview.getWidth());
    System.out.println("Height:" + listview.getHeight());

}