Listview与内容高度相同 [英] Listview same height as content

查看:64
本文介绍了Listview与内容高度相同的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用了自定义listview.内容来自动态,我想要与内容相同的ListView高度.

I used custom listview . Content comes from dynamic I want to same listview height same as content.

我使用了wrap_content,但这无济于事.如果我删除了滚动视图,那么它的工作

I used wrap_content but this does not help If I remove scrollview then its work

代码. 垂直滚动ScrollView不应包含另一个垂直滚动小部件(ListView)"

<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"
    android:background="@drawable/background_img"
    android:scrollbars="none" >

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

<ListView
            android:id="@+id/lstsemtrack"
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
        android:divider="#f2e4e4"
        android:dividerHeight="1dip"
             >
        </ListView>

项目列表

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:orientation="vertical"
    android:padding="10dip"
    android:scrollbars="none" >

    <LinearLayout
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:orientation="horizontal"
        android:weightSum="4" >

        <TextView
            android:id="@+id/txtBiology"
            style="@style/sem_rowtext"
            android:layout_width="0dip"
            android:layout_height="wrap_content"
            android:layout_gravity="center_vertical"
            android:layout_marginRight="5dip"
            android:layout_weight="1"
            android:text="Biology" />

        <TextView
            android:id="@+id/txtClass"
            style="@style/sem_rowtext"
            android:layout_width="0dip"
            android:layout_height="wrap_content"
            android:layout_weight="1"
            android:text="Biology - 101" />

        <TextView
            android:id="@+id/txtGrade"
            style="@style/sem_rowtext"
            android:layout_width="0dip"
            android:layout_height="wrap_content"
            android:layout_weight="1"
            android:text="Grade" />

        <TextView
            android:id="@+id/txtGrade"
            style="@style/sem_rowtext"
            android:layout_width="0dip"
            android:layout_height="wrap_content"
            android:layout_weight="1"
            android:text="Remove" />
    </LinearLayout>

</LinearLayout>

如下所示的输出,我希望与内容相同,没有scrollview

output like below I want same as content no scrollview

推荐答案

使用此代码

public class MyListView  extends ListView {

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

    public MyListView  (Context context) {
        super(context);
    }

    public MyListView  (Context context, AttributeSet attrs, int defStyle) {
        super(context, attrs, defStyle);
    }

    @Override
    public void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
        int expandSpec = MeasureSpec.makeMeasureSpec(Integer.MAX_VALUE >> 2,
                MeasureSpec.AT_MOST);
        super.onMeasure(widthMeasureSpec, expandSpec);
    }
}

这篇关于Listview与内容高度相同的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆