ScrollView嵌套LinearLayout又嵌套ListView的布局样式

159 阅读1分钟

布局文件

<?xml version="1.0" encoding="utf-8"?>
<ScrollView
    xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    tools:context="com.jiawabang.ui.activity.GeRenXinxiActivity">

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:orientation="vertical"
        >

        <ImageView
            android:id="@+id/touxiang_gerenxinxi"
            android:layout_width="90dp"
            android:layout_height="90dp"
            android:layout_gravity="center"
            android:src="@mipmap/ic_launcher"/>

        <ImageView
            android:layout_width="match_parent"
            android:layout_height="15dp"
            android:src="@color/huise2"/> <com.jiawabang.ui.views.MesureListView
            android:layout_width="match_parent"
            android:layout_height="wrap_content"></com.jiawabang.ui.views.MesureListView>

    </LinearLayout>
</ScrollView>

MesureListView类:滚动布局嵌套滚动,避免listview只显示一个条目

package com.jiawabang.ui.views;

import android.content.Context;
import android.util.AttributeSet;
import android.widget.ListView;

/**
 * Created by Administrator on 2016/5/17.
 */
public class MesureListView extends ListView {
    public MesureListView(Context context) {
        super(context);
    }

    public MesureListView(Context context, AttributeSet attrs) {
        super(context, attrs);
    }

    @Override
    protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
        int expandSpec = MeasureSpec.makeMeasureSpec(Integer.MAX_VALUE >> 2,

                MeasureSpec.AT_MOST);

        super.onMeasure(widthMeasureSpec, expandSpec);
    }
}