滚动型和滚动的RelativeLayout本期的ExpandableListView [英] ScrollView and RelativeLayout scrolling issue for ExpandableListView

查看:138
本文介绍了滚动型和滚动的RelativeLayout本期的ExpandableListView的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有下面的布局,显示的联系方式,也有一个扩展列表。但问题是,可扩展列表视图是固定的,但我已经给它FILL_PARENT身高,因此必须充分高度这是可用的。同时滚动视图应用于列出只而不是整个布局。如果任何人有任何想法,请您帮助我。

I am having below layout which displays contact details and also have one expandable list. But the problem is that Expandable List View is fixed but I have given it fill_parent for height so it must take full height which is available. Also the scroll view is applied to list only instead of the whole layout. If anyone has any idea please kindly help me.

<?xml version="1.0" encoding="utf-8"?>
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:ads="http://schemas.android.com/apk/lib/com.google.ads"
    android:id="@+id/scroll"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:background="#FFFFFF"
    android:scrollbars="vertical|horizontal" >

    <RelativeLayout
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
         >

        <RelativeLayout
            android:id="@+id/vsHeader"
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:background="@drawable/header" >

            <Button
                android:id="@+id/btnHome"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_centerVertical="true"
                android:background="@drawable/home"
                android:onClick="btnHomeClick" />
        </RelativeLayout>

        <RelativeLayout
            android:id="@+id/contactheader"
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:layout_below="@id/vsHeader"
            android:padding="5dip" >

            <TextView
                android:id="@+id/txtContactName"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_marginBottom="5dip"
                android:text="Hello Taxi"
                android:textColor="@color/autoText"
                android:textSize="@dimen/text_size_large"
                android:textStyle="bold" />

            <ImageView
                android:id="@+id/img_address"
                android:layout_width="25dip"
                android:layout_height="25dip"
                android:layout_below="@id/txtContactName"
                android:layout_marginBottom="5dip"
                android:contentDescription="@string/content_description"
                android:src="@drawable/address" />

            <TextView
                android:id="@+id/txt_Address"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_below="@id/txtContactName"
                android:layout_marginBottom="15dip"
                android:layout_marginLeft="15dip"
                android:layout_toRightOf="@+id/img_address"
                android:maxLines="5"
                android:singleLine="false"
                android:textColor="@color/autoText" />

            <ImageView
                android:id="@+id/img_phone"
                android:layout_width="25dip"
                android:layout_height="25dip"
                android:layout_below="@id/txt_Address"
                android:layout_marginBottom="5dip"
                android:contentDescription="@string/content_description"
                android:src="@drawable/contact_no" />

            <TextView
                android:id="@+id/txtPhone"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_below="@id/txt_Address"
                android:layout_marginBottom="15dip"
                android:layout_marginLeft="15dip"
                android:layout_toRightOf="@id/img_phone"
                android:textColor="@color/autoText" />

            <ImageView
                android:id="@+id/img_mobile"
                android:layout_width="25dip"
                android:layout_height="25dip"
                android:layout_below="@id/txtPhone"
                android:layout_marginBottom="5dip"
                android:contentDescription="@string/content_description"
                android:src="@drawable/mobile" />

            <TextView
                android:id="@+id/txtmobilenumber"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_below="@id/txtPhone"
                android:layout_marginBottom="15dip"
                android:layout_marginLeft="15dip"
                android:layout_toRightOf="@id/img_mobile"
                android:textColor="@color/autoText" />

            <ImageView
                android:id="@+id/img_web"
                android:layout_width="25dip"
                android:layout_height="25dip"
                android:layout_below="@id/txtmobilenumber"
                android:layout_marginBottom="5dip"
                android:contentDescription="@string/content_description"
                android:src="@drawable/www" />

            <TextView
                android:id="@+id/txtweb"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_below="@id/txtmobilenumber"
                android:layout_marginBottom="15dip"
                android:layout_marginLeft="15dip"
                android:layout_toRightOf="@id/img_web"
                android:textColor="@color/autoText" />

            <ImageView
                android:id="@+id/img_email"
                android:layout_width="25dip"
                android:layout_height="25dip"
                android:layout_below="@id/txtweb"
                android:layout_marginBottom="15dip"
                android:contentDescription="@string/content_description"
                android:src="@drawable/mail" />

            <TextView
                android:id="@+id/txtemail"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_below="@id/txtweb"
                android:layout_marginBottom="15dip"
                android:layout_marginLeft="15dip"
                android:layout_toRightOf="@id/img_email"
                android:textColor="@color/autoText" />

            <Button
                android:id="@+id/btn_rate_it"
                android:layout_width="150dip"
                android:layout_height="wrap_content"
                android:layout_below="@id/img_email"
                android:layout_centerHorizontal="true"
                android:background="@drawable/greenbutton"
                android:text="@string/rate_it"
                android:textColor="#ffffff" />
        </RelativeLayout>

        <ExpandableListView
            android:id="@+id/expandable_list"
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:layout_below="@id/contactheader"
            android:layout_marginTop="10dip"
            android:groupIndicator="@drawable/group_indicator" />
    </RelativeLayout>

</ScrollView>

图片: - 您可以看到,只有列表视图已滚动,所以当你滚动UI变得有些难看。我不想做这样的。我想这整个布局滚动。

推荐答案

我知道这是为时已晚,但我写的其他人说遇到此problem.The问题是当你使用ExpandableListView里面没有定义滚动型ExpandableListView高度correctly.So我计算高度编程是这样的:

I know it is too late but I Wrote for other people that encountering this problem.The problem is when you use ExpandableListView inside Scrollview ExpandableListView height not defined correctly.So I compute height programmatically like this:

//for converting dp to pixel
final float scale = getApplicationContext().getResources().getDisplayMetrics().density;
//when all the headers are Collapse
expListView.getLayoutParams().height=listDataHeader.size()*(int) (43 * scale + 0.5f);

expListView.setOnGroupExpandListener(new OnGroupExpandListener() {

                @Override
                public void onGroupExpand(int groupPosition) {

                    expListView.getLayoutParams().height+=listDataChild.get(listDataHeader.get(groupPosition)).size()*(int) (34 * scale + 0.5f);

                }
            });

            // Listview Group collasped listener
            expListView.setOnGroupCollapseListener(new OnGroupCollapseListener() {

                @Override
                public void onGroupCollapse(int groupPosition) {
                    expListView.getLayoutParams().height-=listDataChild.get(listDataHeader.get(groupPosition)).size()*(int) (34 * scale + 0.5f);

                }
            });

这篇关于滚动型和滚动的RelativeLayout本期的ExpandableListView的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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