今天遇到一个需求就是要在scrolview里面嵌套gridView和listView,而界面确实fragment,这时候诡异的事情发生了,当在Handler里面刷新网络请求返回来的数据setAdapter时发现listView的高度消失了,可能和gridView也是设置了高度为最大值有关吧!最后解决办法在handler里面再次动态设置scrolview的高度。
布局文件如下:
<?xml version="1.0" encoding="utf-8"?>
<!-- 推荐 -->
<com.handmark.pulltorefresh.library.PullToRefreshScrollView xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:ptr="http://schemas.android.com/apk/res-auto"
android:id="@+id/pull_refresh_scrollview"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fillViewport="true"
android:orientation="vertical"
android:scrollbars="none"
ptr:ptrAnimationStyle="flip"
ptr:ptrMode="both" >
<LinearLayout
android:id="@+id/layout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@color/white"
android:orientation="vertical" >
<tv.acfun.im.support.widget.customview.BannerView
android:id="@+id/bannerView"
android:layout_width="match_parent"
android:layout_height="@dimen/banner_pic_height" />
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginBottom="5dp"
android:layout_marginLeft="@dimen/marginLeft"
android:layout_marginRight="@dimen/marginLeft"
android:layout_marginTop="10dp"
android:orientation="horizontal" >
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="@drawable/public_xinfan" />
<TextView
android:id="@+id/title"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_weight="1"
android:gravity="left|center_vertical"
android:text="本季新番"
android:textColor="@color/drama_title_color"
android:textSize="16sp" />
<TextView
android:id="@+id/more"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:gravity="center"
android:text="更多"
android:textColor="@color/gray2" />
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical"
android:background="@drawable/public_more_wonderful" />
</LinearLayout>
<tv.acfun.im.support.widget.customview.DramaGridView
android:id="@+id/grid"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="@dimen/marginLeft"
android:layout_marginRight="@dimen/marginLeft"
android:cacheColorHint="@android:color/transparent"
android:horizontalSpacing="10dp"
android:listSelector="@android:color/transparent"
android:numColumns="4"
/>
<TextView
android:layout_width="match_parent"
android:layout_height="10dp"
android:layout_marginBottom="@dimen/margin_top"
android:layout_marginTop="@dimen/margin_top"
android:background="#e8e8e8" />
<tv.acfun.im.support.widget.customview.MyDrameFirstListView
android:id="@+id/myListView"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_marginBottom="60dp"
android:layout_marginLeft="@dimen/marginLeft"
android:layout_marginRight="@dimen/marginLeft"
android:cacheColorHint="@android:color/transparent"
android:divider="#dfdfdf"
android:dividerHeight="10dp"
android:listSelector="@android:color/transparent" />
</LinearLayout>
</com.handmark.pulltorefresh.library.PullToRefreshScrollView>
handler里面的代码如下:
VideoListPojo vlp = (VideoListPojo) rv.rspData;
System.out.println(vlp.ranking.size() + "排行榜");
// 添加假的实现
List<Test_item_pojo> list = new ArrayList<Test_item_pojo>();
Test_item_pojo tip = new Test_item_pojo();
tip.imgUrl1 = vlp.ranking.get(0).cover;
tip.imgUrl2 = vlp.ranking.get(1).cover;
tip.imgUrl3 = vlp.ranking.get(2).cover;
tip.imgUrl4 = vlp.ranking.get(3).cover;
tip.title1 = vlp.ranking.get(0).name;
tip.title2 = vlp.ranking.get(1).name;
tip.title3 = vlp.ranking.get(2).name;
tip.title4 = vlp.ranking.get(3).name;
list.add(tip);
listView.setAdapter(new DramaFirstAda(getContext(),
list));
// listView.setLayoutParams(new
// LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT,
// 2000));
// setListViewHeightBasedOnChildren(listView);
LinearLayout.LayoutParams parmas = new LinearLayout.LayoutParams(
LinearLayout.LayoutParams.MATCH_PARENT,
LinearLayout.LayoutParams.MATCH_PARENT);
parmas.bottomMargin = 80;
listView.setLayoutParams(parmas);
pullToRefreshScroll
.setLayoutParams(new LinearLayout.LayoutParams(
LinearLayout.LayoutParams.MATCH_PARENT,
LinearLayout.LayoutParams.MATCH_PARENT));