我在ScrollView上扩充视图。
我需要获取事件,当滚动其中一个视图(例如,最后一个或特殊类型)变为可见时(在屏幕区域中)。
答案 0 :(得分:0)
如果视图更改了可见性,则会调用onlayout方法,您可以尝试覆盖该方法并检查其状态。
答案 1 :(得分:0)
您需要覆盖视图的onVisibilityChanged()
。当其中一个视图的祖先改变可见性时,也会调用此方法。
答案 2 :(得分:-1)
这让我夸大了我的GridView并获得了你想要的东西
public class MyGrideView extends GridView {
boolean expanded = false;
public MyGrideView(Context context) {
super(context);
}
public MyGrideView(Context context, AttributeSet attrs) {
super(context, attrs);
}
public MyGrideView(Context context, AttributeSet attrs, int defStyle) {
super(context, attrs, defStyle);
}
public boolean isExpanded() {
return expanded;
}
@Override
public void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
// HACK! TAKE THAT ANDROID!
if (isExpanded()) {
// Calculate entire height by providing a very large height hint.
// But do not use the highest 2 bits of this integer; those are
// reserved for the MeasureSpec mode.
int expandSpec = MeasureSpec.makeMeasureSpec(
Integer.MAX_VALUE >> 2, MeasureSpec.AT_MOST);
super.onMeasure(widthMeasureSpec, expandSpec);
ViewGroup.LayoutParams params = getLayoutParams();
params.height = getMeasuredHeight();
} else {
super.onMeasure(widthMeasureSpec, heightMeasureSpec);
}
}
public void setExpanded(boolean expanded) {
this.expanded = expanded;
}
}