android中控制ListView宽度和高度
生活随笔
收集整理的這篇文章主要介紹了
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宽度和高度的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: hdu3333(线段树)
- 下一篇: 坑爹的SQL ISNUMERIC