============问题描述============
给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 内部机制问题