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>
  • 相关阅读:
    SpringBoot基本配置
    Profile配置
    vue2.X使用LeanCloud
    Vue学习一 创建项目及项目总览
    工具使用:使用frp,反向代理内网到公网
    Unity的学习笔记(摇杆制作)
    Unity的学习笔记(XLua的初学用法并在lua中使用unity周期函数)
    Unity的学习笔记(射线检测)
    Unity的学习笔记(鼠标移动控制视角移动)
    Unity的学习笔记(UGUI文本逐个字输出)
  • 原文地址:https://www.cnblogs.com/jiuqing/p/4036817.html
Copyright © 2011-2022 走看看