
通常情況下ListView的android:layout_height屬性我們都設(shè)置成"fill_parent",但是這樣一來,它就會占據(jù)整個屏幕,如果它下面還有控件的話,就會被它“擠到”外面去。如何解決這種情況呢?表面上使用LinearLayout是最簡單的,但就會出現(xiàn)上面的情形。那就使用RelativeLayout吧。
<?xml version="1.0" encoding="utf-8"?> <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="fill_parent" android:layout_height="fill_parent" > <Button android:id="@+id/btn_1" android:layout_width="fill_parent" android:layout_height="wrap_content" android:text="click_1" android:layout_alignParentLeft="true" android:layout_alignParentBottom="true" /> <Button android:id="@+id/btn_0" android:layout_width="fill_parent" android:layout_height="wrap_content" android:text="click_0" android:layout_above="@id/btn_1" android:layout_alignParentLeft="true" /> <ListView android:id="@+id/listview" android:layout_width="fill_parent" android:layout_height="fill_parent" android:layout_above="@id/btn_0" android:layout_alignParentLeft="true" android:layout_alignParentTop="true" /> </RelativeLayout>
上面的布局僅作參考!
當(dāng)然如果將ListView換成ScrollView也是一樣的,這里只起到拋磚引玉的目的。
另外,你也可以在ListView中使用android:layout_weight="1",這樣就可以將它放在LinearLayout,這樣是最簡單的!
更多文章、技術(shù)交流、商務(wù)合作、聯(lián)系博主
微信掃碼或搜索:z360901061

微信掃一掃加我為好友
QQ號聯(lián)系: 360901061
您的支持是博主寫作最大的動力,如果您喜歡我的文章,感覺我的文章對您有幫助,請用微信掃描下面二維碼支持博主2元、5元、10元、20元等您想捐的金額吧,狠狠點擊下面給點支持吧,站長非常感激您!手機(jī)微信長按不能支付解決辦法:請將微信支付二維碼保存到相冊,切換到微信,然后點擊微信右上角掃一掃功能,選擇支付二維碼完成支付。
【本文對您有幫助就好】元
