android view被挡住,Android View遮挡问题解决方案
以GridView为例重载GridView实现将指定View置顶,以免放大时被其他View遮挡,其他布局也可类似实现方案一:package com.example.gridview;import android.content.Context;import android.graphics.Canvas;import android.util.AttributeSet;import android
以GridView为例
重载GridView
实现将指定View置顶,以免放大时被其他View遮挡,其他布局也可类似实现
方案一:
package com.example.gridview;
import android.content.Context;
import android.graphics.Canvas;
import android.util.AttributeSet;
import android.util.Log;
import android.view.View;
import android.widget.GridView;
public class MyGridView extends GridView {
public MyGridView(Context context, AttributeSet attrs) {
super(context, attrs);
// TODO Auto-generated constructor stub
setChildrenDrawingOrderEnabled(true);
}
//设置要设为topView的view
public void setTopView(View v)
{
for(int i = 0; i < getChildCount(); i++)
{
if(getChildAt(i) == v)
{
postion = i;
break;
}
}
}
privateintpostion= -1;
//修改绘制顺序
@Override
protected int getChildDrawingOrder(int childCount, int i) {
// TODO Auto-generated method stub
if(childCount > 0 && postion != -1)
{
if(i== postion)
{
return childCount - 1;
}else if(i == childCount - 1)
{
returnpostion;
}else {
return i;
}
}
returni;
}
}
方案二:
重载dispatchDraw,当全部子View绘制后,再次绘制选定的View
@Override
protected void dispatchDraw(Canvas canvas) {
super.dispatchDraw(canvas);
drawChild(canvas, v, v.getDrawingTime());
}
实现将指定View置顶,以免放大时被遮挡
更多推荐
所有评论(0)