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

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值