簡體   English   中英

如何設置通過Java代碼動態創建的ListView的高度?

[英]How to set height for the listview that created dynamically through java code?

我試圖設置通過Java代碼動態創建的listview的高度。 我在滾動視圖中使用3個列表視圖(一個在另一個列表下面)(以避免隱藏列表)。 如果我使用滾動視圖,則無法查看listviews的所有列表項。是否有任何想法通過android中的java編碼設置這3個列表視圖的高度? 非常感謝您的任何幫助,並在此先感謝...

不要將ListViews放在ScrollViews中! 在從列表視圖的開發人員詳細信息處於語音可用列表視圖的世界

通過使用layoutWeight參數,可以使三個ListView在屏幕上共享空間。

進行這樣的布局(您也可以使用代碼):

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<ListView android:id="@+id/listView1" android:layout_height="wrap_content" android:layout_width="fill_parent" android:layout_weight="1"></ListView>
<ListView android:id="@+id/listView2" android:layout_height="wrap_content" android:layout_width="fill_parent" android:layout_weight="1"></ListView>
<ListView android:id="@+id/listView3" android:layout_height="wrap_content" android:layout_width="fill_parent" android:layout_weight="1"></ListView>
</LinearLayout>

在這里,每個ListView占用可用空間的三分之一(所有權重均設置為1)。

要在代碼中設置layoutWeight,請以以下行為例:

listview1.setLayoutParams(new LinearLayout.LayoutParams(LinearLayout.LayoutParams.WRAP_CONTENT, LinearLayout.LayoutParams.WRAP_CONTENT, 1f));

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM