zoukankan      html  css  js  c++  java
  • ScrollView里面添加ListView时,解决ListView的显示问题

    在ScrollView里面添加ListView时,看了很多其他人的讲述,好像ListView只显示一条信息,为此简单新写了一个ListView控件,在布局文件里调用就可以了,代码如下:

    1:ScrollViewWithListView.java

     1 package com.ghp.view;
     2 
     3 import android.widget.ListView;
     4 
     5 /**
     6  * 
     7  * @Description: scrollview中内嵌listview的简单实现
     8  * 
     9  * @File: ScrollViewWithListView.java
    10  * 
    11  */
    12 public class ScrollViewWithListView extends ListView {
    13 
    14     public ScrollViewWithListView(android.content.Context context,
    15             android.util.AttributeSet attrs) {
    16         super(context, attrs);
    17     }
    18 
    19     /**
    20      * Integer.MAX_VALUE >> 2,如果不设置,系统默认设置是显示两条
    21      */
    22     public void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
    23         int expandSpec = MeasureSpec.makeMeasureSpec(Integer.MAX_VALUE >> 2,
    24                 MeasureSpec.AT_MOST);
    25         super.onMeasure(widthMeasureSpec, expandSpec);
    26 
    27     }

    2:布局文件里使用ListView控件

     1 <ScrollView
     2         android:id="@+id/recipeContentScrollView"
     3         android:layout_width="match_parent"
     4         android:layout_height="match_parent"
     5         android:layout_alignParentLeft="true"      
     6         android:background="#f7f3e8"
     7         android:orientation="vertical"
     8         android:scrollbars="none" >
     9     <RelativeLayout
    10             android:id="@+id/recipe"
    11             android:layout_width="match_parent"
    12             android:layout_height="match_parent" >
    13 ……
    14 ……
    15 ……
    16         <com.ghp.view.ScrollViewWithListView
    17                     android:id="@+id/recipe_main_material_ListView"
    18                     android:layout_width="match_parent"
    19                     android:layout_height="match_parent"
    20                     android:layout_below="@+id/material"
    21                     android:layout_marginLeft="40dp"
    22                     android:layout_marginRight="40dp"
    23                     android:layout_marginTop="5dp"
    24                     android:divider="#ffdddddd"
    25                     android:dividerHeight="0.5dp"
    26                     android:fadingEdge="none"
    27                     android:scrollbars="none" />
    28     </RelativeLayout>
    29 </ScrollView>
  • 相关阅读:
    nodejs 核心模块crypto
    es6新特性学习
    nodejs 常用全局包
    ionic+angular+cordova 安卓环境搭建
    谷歌浏览器调试保存到文件
    Linux命令
    Linux中用户管理详解(上)-Linux学习日记
    liunx下忘记root密码的解决方法
    cvCanny的参数
    VC运行时库(/MD、/MT等)
  • 原文地址:https://www.cnblogs.com/jiuqing/p/4036817.html
Copyright © 2011-2022 走看看