日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

android中控制ListView宽度和高度

發布時間:2024/9/5 编程问答 32 豆豆
生活随笔 收集整理的這篇文章主要介紹了 android中控制ListView宽度和高度 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

============問題描述============


給listveiw填充item布局都是wrap_content,listview自身也使用wrap_content,可是實際顯示效果listview寬度都是全屏,求解決辦法
item布局:
<RelativeLayout?xmlns:android="http://schemas.android.com/apk/res/android"android:layout_width="wrap_content"android:layout_height="wrap_content"><TextView?android:id="@+id/video_name"android:layout_width="wrap_content"android:layout_height="wrap_content"android:textColor="#ffffff"/></RelativeLayout>

listview布局:
<RelativeLayout?android:id="@+id/video_list_box"?android:layout_width="wrap_content"android:layout_height="wrap_content"android:background="@drawable/list_bg"android:layout_alignParentRight="true"android:layout_below="@id/title_box"><ListView?android:id="@+id/video_list_view"android:layout_width="wrap_content"android:layout_height="wrap_content"></ListView></RelativeLayout>

============解決方案1============


布局這種東西?單個的情況下還好說,??一旦組合起來,?各種布局相互嵌套?就不太容易找到規律,?需要慢慢調整?

你把整個布局文件貼上來?看看

============解決方案2============


可以在代碼里面控制高寬,先取出屏幕的寬高??進行設置

============解決方案3============


引用?5?樓?Augleo1989?的回復:主layout:
<RelativeLayout?xmlns:android="http://schemas.android.com/apk/res/android"xmlns:tools="http://schemas.android.com/tools"android:layout_width="match_parent"android:layout_height="match_parent"tools:context=".MainActivity"?><RelativeLayout?android:id="@+id/video_list_box"?android:layout_width="wrap_content"android:layout_height="wrap_content"android:background="@drawable/list_bg"android:layout_alignParentRight="true"><ListView?android:id="@+id/video_list_view"android:layout_width="wrap_content"android:layout_height="wrap_content"></ListView></RelativeLayout></RelativeLayout>

item布局:
<?xml?version="1.0"?encoding="utf-8"?><RelativeLayout?xmlns:android="http://schemas.android.com/apk/res/android"android:layout_width="wrap_content"android:layout_height="wrap_content"><TextView?android:id="@+id/video_name"android:layout_width="wrap_content"android:layout_height="wrap_content"android:textColor="#ffffff"/></RelativeLayout>
實現效果就是在屏幕右側顯示一個菜單列表,長寬跟背景圖list_bg一致

你把?ListView?的寬度?設置為?200dp?把?item?數值設置成?100dp?看看能不能達到你想要的效果?,?如果達不到?,?說明是?android?內部機制問題

轉載于:https://www.cnblogs.com/lianxu61/p/4083137.html

總結

以上是生活随笔為你收集整理的android中控制ListView宽度和高度的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。