的ListView在Android上运行时设置身高 [英] Set Height of ListView at run time in android

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

问题描述

如何设置的ListView的高度。

How to set Height of ListView.

XML code(这code是工作的罚款和固定高度200 DIP)

XML Code (This code is working fine and fixed height as 200 dip)

<LinearLayout
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:padding="5dip"
    android:orientation="vertical" >
    <ListView
        android:id="@+id/dialog_ListView"
        android:layout_width="wrap_content"
        android:layout_height="200dip"
        android:padding="5dip"
        android:layout_weight="1"
        android:dividerHeight="5dip"
        android:divider="@android:color/transparent" />        
</LinearLayout>

Android的code(这code没有固定的宽度和高度)

Android Code (This code not fixed width and height)

convertView = mInflater.inflate( R.layout.dialog_page, null );
convertView.setLayoutParams( new ListView.LayoutParams( 200, 300) );

Android的code(这codeI得到错误信息)

Android Code (This code i got Error Message)

convertView = mInflater.inflate( R.layout.lock_file_page, parent );
convertView.setLayoutParams( new ListView.LayoutParams( 200, 300) );

错误信息

java.lang.UnsupportedOperationException: addView(View, LayoutParams) is not supported in AdapterView

如何修复宽度和高度运行。

How do fix Width and Height at Runtime.

在此先感谢。

推荐答案

试试这个code ..

Try This code..

 LayoutParams lp = (LayoutParams) mListView.getLayoutParams();
 lp.height = 300;
 mListView.setLayoutParams(lp);

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

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