zoukankan      html  css  js  c++  java
  • 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 内部机制问题
  • 相关阅读:
    团队项目 NABCD介绍
    java web项目通过外网ip访问
    第七周总结
    全球疫情可视化展示
    第六周总结
    软工小队——团队介绍
    Android端疫情数据统计与现实——Android连接Mysql
    android SDK SDK Manager.exe 无法打开,一闪而过最终解决办法 (转)
    第五周总结
    Java代码编写规范(转)
  • 原文地址:https://www.cnblogs.com/lianxu61/p/4035734.html
Copyright © 2011-2022 走看看