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>
  • 相关阅读:
    RabbitMq使用说明
    php使用rabbitmq需安装amqp拓展协议
    新建springboot web项目pom报错
    HttpRunner Manager 接口自动化平台搭建
    数据库存储过程进行批量插入数据
    Windows系统下Robot Framework的安装
    利用Charles模拟客户端弱网环境进行弱网测试
    JMeter进行简单的接口压测
    JMeter的安装和使用
    grep, sed 和 awk 学习总结
  • 原文地址:https://www.cnblogs.com/jiuqing/p/4036817.html
Copyright © 2011-2022 走看看