实习连载日记3.16-我真垃圾

本文详细探讨了 PullToRefreshListView 在使用过程中出现的抖动问题,并尝试通过重写 onSizeChanged 方法来解决该问题。同时,文中还讨论了如何保持下拉刷新功能的同时解决抖动现象。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

  • 经验老道的编程
  • tablayout
  • equalsIgnoreCase
    ##杂谈
    什么也不想说了,pulltorefreshlistview有bug。

一位前辈让我改个xml。但是这个xml是个listview中的item,这个listview正是pulltorefreshlistview。而pulltorefreshlistview有bug,不过我改不出来,又归到那个前辈手中。
由于pull这个三方在底层的PullToRefreshBase 类中有这么一个方法。

@Override
	protected final void onSizeChanged(int w, int h, int oldw, int oldh) {
		if (DEBUG) {
			Log.d(LOG_TAG, String.format("onSizeChanged. W: %d, H: %d", w, h));
		}

		super.onSizeChanged(w, h, oldw, oldh);

			// We need to update the header/footer when our size changes
			refreshLoadingViewsSize();

			// Update the Refreshable View layout
			refreshRefreshableViewSize(w, h);

			/**
			 * As we're currently in a Layout Pass, we need to schedule another one
			 * to layout any changes we've made here
			 */
			post(new Runnable() {
				@Override
				public void run() {
					requestLayout();
				}
			});
	}

而这个方法的refreshRefreshableViewSize中有一个requestlayout,这样就会造成当我动态变换布局时,有抖动的效果。

我的布局应该是这样:
我来描述一下吧,点击actionbar中的垃圾桶图标,listview的每一个item左侧就会出现可供标记的圆点。

每次圆点出现和隐藏的时候,会抖一下。。。

至于怎么解决,之前有人重写了这个pulltorefreshbase。是这样的。

//onSizeChange 时是否刷新页面
	public void setCanResize(boolean canResize){
		mCanResize = canResize;
	}

	@Override
	protected final void onSizeChanged(int w, int h, int oldw, int oldh) {
		if (DEBUG) {
			Log.d(LOG_TAG, String.format("onSizeChanged. W: %d, H: %d", w, h));
		}

		super.onSizeChanged(w, h, oldw, oldh);

		if (mCanResize) {
			// We need to update the header/footer when our size changes
			refreshLoadingViewsSize();

			// Update the Refreshable View layout
			refreshRefreshableViewSize(w, h);

			/**
			 * As we're currently in a Layout Pass, we need to schedule another one
			 * to layout any changes we've made here
			 */
			post(new Runnable() {
				@Override
				public void run() {
					requestLayout();
				}
			});
		}
	}

加了一个标记位,在外面的fragment中设置为false。这样是不抖动了,但是下拉刷新功能没有了。。。原因猜测是这样:在pulltorefreshbase里的refreshLoadingViewsSize();这个方法没有被执行,因为这个方法是重新绘制了一下loadingview,也就是下拉刷新时的图标那个控件。

当我改成:

//onSizeChange 时是否刷新页面
	public void setCanResize(boolean canResize){
		mCanResize = canResize;
	}

	@Override
	protected final void onSizeChanged(int w, int h, int oldw, int oldh) {
		if (DEBUG) {
			Log.d(LOG_TAG, String.format("onSizeChanged. W: %d, H: %d", w, h));
		}

		super.onSizeChanged(w, h, oldw, oldh);

		if (mCanResize) {
			// We need to update the header/footer when our size changes
			refreshLoadingViewsSize();

			// Update the Refreshable View layout
			refreshRefreshableViewSize(w, h);

			/**
			 * As we're currently in a Layout Pass, we need to schedule another one
			 * to layout any changes we've made here
			 */
			post(new Runnable() {
				@Override
				public void run() {
					requestLayout();
				}
			});
		}else {
			refreshLoadingViewsSize();
		}
	}

改成这样的时候,又出现新问题了,每次点击actionbar中垃圾桶的图标时,都会向下移动一条距离,再次点击,然后又向上一块。

疯了,不知道怎么办,谁能解决告诉我。

经验老道的编程

在布局中有一个需求:在一个layout中,有隐藏的右侧的layout,无论右侧的layout是否可见,都有一个图片居中在这个layout的左边的区域内。

一位老司机是这样解决的。

 <FrameLayout
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:layout_toLeftOf="@+id/right_to_icon_layout">

            <ImageView
                android:id="@+id/primary_icon"
                android:layout_width="28dp"
                android:layout_height="28dp"
                android:layout_gravity="center"
                android:contentDescription="@null"
                android:scaleType="centerInside"
                android:src="@drawable/rel_icon_video" />

        </FrameLayout>

套一个帧布局,位于右侧layout(@+id/right_to_icon_layout)的左侧。无论右侧layout出现与否,这个图片都会居中于我们想要的位置。

要是我的思路的话,就要用两个图片来解决了。

###tablayout

还有些属性不知道啊,复习复习复习
http://www.jianshu.com/p/2b2bb6be83a8
###equalsIgnoreCase
不区分大小写比较字符

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值