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>
  • 相关阅读:
    cocos2d-x学习笔记(贪吃蛇代码)
    jQuery中animate的height的自适应
    [Docker02]Docker_registry
    [Docker03] Deploy LNMP on Docker
    Python OS Module
    前端设计框架
    Ansible权威指南-读书笔记
    python+selenium之悠悠博客学习笔记
    jenkins入门
    sed
  • 原文地址:https://www.cnblogs.com/jiuqing/p/4036817.html
Copyright © 2011-2022 走看看