zoukankan      html  css  js  c++  java
  • Android开发遇到的问题:不给include设置width、height,导致ListView GridView内容无法显示

    我的目的是做一个带有TextView的ListView列表页面。

    以下是这个页面的xml:

    <?xml version="1.0" encoding="utf-8"?>
    <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:orientation="vertical" >
        
        <include 
            layout="@layout/head"/>
        
        <GridView
            android:id="@+id/gv_home" 
            android:numColumns="3"
            android:layout_width="match_parent"
            android:layout_height="match_parent" />
            
    </LinearLayout>

    以下是这个页面的head.xml:

    <?xml version="1.0" encoding="utf-8"?>
    <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:orientation="vertical" >
        
        <TextView 
            android:id="@+id/tv_head"
            android:text="@string/loading"
            android:textSize="22sp"
            android:background="@color/bg_color"
            android:textColor="#000000"
            android:layout_width="match_parent"
            android:gravity="center"
            android:layout_height="55dip"/>
    
    </RelativeLayout>

    可以看到我设置了head.xml宽高都是match_parent,而不给Include设定宽高,那么相当于给Include设定了match_parent,这样导致下面的ListView被挤到屏幕下面了。

    导致ListView  GridView的内容不显示。

    解决办法:

    1. 给Include设定高度为wrap_content

    2. 给head.xml的RelativeLayout设定高度为wrap_content

  • 相关阅读:
    关于Date相关函数在火狐Firefox和谷歌Chrome下的不同
    一键部署 LNMP 建站环境
    Python 返回值、方法和函数的区别
    Python中万物皆对象?的理解
    Python 实用小工具 练习(2)
    Chrome浏览器F12开发者工具使用教程博客汇总
    觅风易语言[21-24、30]
    觅风易语言[1-10]
    觅风易语言[11-20]
    Python Byte类型(API系列)
  • 原文地址:https://www.cnblogs.com/hoosway/p/4925963.html
Copyright © 2011-2022 走看看