android中控制ListView寬度和高度

來源:互聯網
上載者:User

標籤:android   http   color   io   ar   使用   sp   檔案   on   

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


給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 內部機制問題

android中控制ListView寬度和高度

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.