Android:fadeIn选定行
我的listview与此类似: 添加代码,虽然不多,但可能有帮助: 自定义适配器:Android:fadeIn选定行,android,listview,animation,Android,Listview,Animation,我的listview与此类似: 添加代码,虽然不多,但可能有帮助: 自定义适配器: public class MyAdapter extends BaseAdapter{ private LayoutInflater mInflater; private Animation fadeIn; private Animation fadeOut; public MyAdapter(Activity c) { mInflater = c.getLayoutInflater();
public class MyAdapter extends BaseAdapter{
private LayoutInflater mInflater;
private Animation fadeIn;
private Animation fadeOut;
public MyAdapter(Activity c) {
mInflater = c.getLayoutInflater();
fadeIn = AnimationUtils.loadAnimation(c.getApplicationContext(), R.anim.alpha_show);
fadeIn.setFillAfter(true);
fadeOut = AnimationUtils.loadAnimation(c.getApplicationContext(), R.anim.alpha_dissappear);
fadeOut.setFillAfter(true);
}
public int getCount() {
return MainButtonsList.getList().getSize() +
GlobalPrefs.getEmptyRowsAtEnd() +
GlobalPrefs.getEmptyRowsAtStart();
}
public View getView(int position, View v, ViewGroup parent) {
View convertView = v;
if (convertView == null) {
convertView = mInflater.inflate(R.layout.main_list_item, null);
}
ImageView iv = (ImageView) convertView.findViewById(R.id.image);
if ((position > GlobalPrefs.getEmptyRowsAtStart() - 1) && (position < getCount() - GlobalPrefs.getEmptyRowsAtEnd())) {
iv.setImageResource(MainButtonsList.getList().getListImageResource(position - GlobalPrefs.getEmptyRowsAtStart()));
iv.setAlpha(255);
iv.setTag(MainButtonsList.UNPRESSED_BUTTON_TAG);
} else {
iv.setTag(MainButtonsList.UNUSED_BUTTON_TAG);
iv.setAlpha(0);
iv.setVisibility(0);
iv.setClickable(false);
iv.setImageResource(R.drawable.logo_list_null);
}
iv.setMaxHeight(GlobalPrefs.getRowHeight());
iv.setMaxWidth(GlobalPrefs.getRowWidth());
iv.setBackgroundResource(0);
return convertView;
}
public Object getItem(int position) {
return MainButtonsList.getList().getObject(position);
}
public long getItemId(int position) {
return position;
}
}
公共类MyAdapter扩展了BaseAdapter{
私人停车场;
私人动画;
私人动画淡出;
公共MyAdapter(活动c){
mInflater=c.getLayoutInflater();
fadeIn=AnimationUtils.loadAnimation(c.getApplicationContext(),R.anim.alpha_-show);
fadeIn.setFillAfter(true);
fadeOut=AnimationUtils.loadAnimation(c.getApplicationContext(),R.anim.alpha_dissequent);
淡出。setFillAfter(真);
}
public int getCount(){
返回MainButtonsList.getList().getSize()+
GlobalPrefs.getEmptyRowsAtEnd()+
GlobalPrefs.getEmptyRowsAtStart();
}
公共视图getView(内部位置、视图v、视图组父视图){
视图convertView=v;
if(convertView==null){
convertView=mInflater.充气(R.layout.main\u列表项,空);
}
ImageView iv=(ImageView)convertView.findViewById(R.id.image);
if((位置>GlobalPrefs.getEmptyRowsAtStart()-1)&&(位置
自定义列表视图:
public class CopyOfListView3d extends ListView{
private final Camera mCamera = new Camera();
private final Matrix mMatrix = new Matrix();
private Context context;
private Paint mPaint;
public CopyOfListView3d(Context context, AttributeSet attrs) {
super(context, attrs);
this.context = context;
this.setChildrenDrawingOrderEnabled(true);
}
@Override
protected int getChildDrawingOrder (int childCount, int i) {
//sets order number to each child, so makes overlap and center is always on top
}
@Override
protected boolean drawChild(Canvas canvas, View child, long drawingTime) {
// get top left coordinates
boolean isCenter = false;
final int top = child.getTop();
final int bottom = child.getBottom();
Bitmap bitmap = child.getDrawingCache();
if (bitmap == null) {
child.setDrawingCacheEnabled(true);
child.buildDrawingCache();
bitmap = child.getDrawingCache();
}
final int centerY = child.getHeight() / 2;
final int centerX = child.getWidth() / 2;
final int radius = getHeight() / 2;
final int absParentCenterY = getTop() + getHeight() / 2;
final int absChildCenterY = child.getTop() + centerY;
final int distanceY = (absParentCenterY - absChildCenterY) / 2;
final int absDistance = Math.min(radius, Math.abs(distanceY));
final float translateZ = (float) Math.sqrt((radius * radius) - (absDistance * absDistance));
mCamera.save();
float myTranslateX = (float) (translateZ * (1.5f));
int density = GlobalPrefs.getDensity();
if (density < DisplayMetrics.DENSITY_LOW) {
myTranslateX = (float) myTranslateX - 80;
} else if (density == DisplayMetrics.DENSITY_LOW) {
myTranslateX = (float) myTranslateX - GlobalPrefs.getScreenWidth() + density + 40;
} else if (density <= DisplayMetrics.DENSITY_MEDIUM) {
myTranslateX = (float) myTranslateX - ((float)(GlobalPrefs.getScreenWidth()*0.75)) + density/2;
} else
if (density <= DisplayMetrics.DENSITY_HIGH) {
myTranslateX = (float) myTranslateX - 320;
} else
if (density > DisplayMetrics.DENSITY_HIGH) {
//Log.i("density", "this is more than high");
myTranslateX = (float) myTranslateX;
}
if ((top < absParentCenterY) && (bottom > absParentCenterY)) {
//make center row bigger
isCenter = true;
mCamera.translate((float) myTranslateX, 0, (float) -160);//130
child.setPressed(true);
child.setTag(MainButtonsList.PRESSED_BUTTON_TAG);
}
else {
//top
child.setTag(MainButtonsList.UNPRESSED_BUTTON_TAG);
child.setPressed(false);
mCamera.translate((float) myTranslateX, 0, -150);//120;
};
mCamera.getMatrix(mMatrix);
mCamera.restore();
// create and initialize the paint object
if (mPaint == null) {
mPaint = new Paint();
mPaint.setAntiAlias(true);
mPaint.setFilterBitmap(true);
}
//calculates alpha for each row, so far from center, rows are barely visible
mPaint.setAlpha(calculateAlpha(absChildCenterY));
mMatrix.postTranslate((float) (-centerX * 1.5f), top);
canvas.drawBitmap(bitmap, mMatrix, mPaint);
return false;
}
}
公共类CopyOfListView3d扩展ListView{
专用最终摄像头mCamera=新摄像头();
私有最终矩阵mMatrix=新矩阵();
私人语境;
私人油漆;
公共CopyOfListView3d(上下文、属性集属性){
超级(上下文,attrs);
this.context=上下文;
此.setChildrenDrawingOrderEnabled(true);
}
@凌驾
受保护的int getChildDrawingOrder(int childCount,int i){
//为每个子项设置订单号,以便使重叠和中心始终位于顶部
}
@凌驾
受保护的布尔drawChild(画布、视图子对象、长drawingTime){
//获取左上角的坐标
布尔值isCenter=false;
final int top=child.getTop();
final int bottom=child.getBottom();
位图位图=child.getDrawingCache();
如果(位图==null){
setDrawingCacheEnabled(true);
buildDrawingCache();
位图=child.getDrawingCache();
}
final int centerY=child.getHeight()/2;
final int centerX=child.getWidth()/2;
最终整数半径=getHeight()/2;
final int absParentCenterY=getTop()+getHeight()/2;
final int absChildCenterY=child.getTop()+centerY;
最终整数距离=(absparentcentry-abschildcentry)/2;
最终int absDistance=Math.min(半径,Math.abs(距离));
最终浮点translateZ=(float)Math.sqrt((半径*半径)-(absDistance*absDistance));
mCamera.save();
float myTranslateX=(float)(translateZ*(1.5f));
int density=GlobalPrefs.getDensity();
if(密度
它们由图像视图组成,其中白色为选中状态,蓝色为未选中状态,我通过屏幕坐标更改选中/未选中,因此始终选中中心
我有一个自定义3dListView,它扩展了ListView并制作了自定义适配器,在这里我将ImageView设置为行。代码太多,无法显示,但有相当简单的
其中一个可能是有用的:
1) 如何使中心行淡入(也可能淡出)(在提供父行或子行计数时,我可以找到哪一行是中心行)?(更好)
2) 如果有任何OnStateChange监听器可以监听view的按键,这也会很有帮助。然后,当按下view时,我可以随时淡入淡出,当松开按下时,我可以淡入淡出。您需要在listview的适配器中淡入淡出 在适配器中
private List<YourListObject> deleteItems;
// Constructor to init list and other vars
@Override
public View getView(int position, View convertView, ViewGroup parent) {
// Draw stuff
// including your object
for(YourListObject obj : deleteItems){
if(currentObj.equals(obj)){
Animation fadeOutAnimation = new AlphaAnimation(1.0f, 0.0f);
fadeOutAnimation.setDuration(300);
DeleteAnimationListener listener = new DeleteAnimationListener(currentObj);
fadeOutAnimation.setAnimationListener(listener);
someView.startAnimation(fadeOutAnimation);
}
}
return someView;
}
public void remove(YourListObject obj){
deleteItems.add(obj);
notifyDataSetChanged();
}
protected class DeleteAnimationListener extends EndAnimationListener {
private final YourListObject obj;
public DeleteAnimationListener(YourListObject obj) {
this.obj = obj;
}
@Override
public void onAnimationEnd(Animation animation) {
yourObjects.remove(obj);
deleteItems.remove(obj);
notifyDataSetChanged();
}
};
私有列表删除项;
//初始化列表和其他变量的构造函数
@凌驾
公共视图getView(int位置、视图转换视图、视图组父视图){
//画画
//包括你的目标
对于(YourListObject对象:deleteItems){
如果(当前对象等于(对象)){
动画淡出动画=新的AlphaAnimation(1.0f,0.0f);
淡出激活。设置持续时间(300);
DeleteAnimationListener=新建DeleteAnima
final ImageView iv = (ImageView) child.findViewById(R.id.image);
child.setTag(MainButtonsList.PRESSED_BUTTON_TAG);
Animation anim = fadeOut();
anim.setAnimationListener(new Animation.AnimationListener() {
public void onAnimationStart(Animation animation) {
// TODO Auto-generated method stub
}
public void onAnimationRepeat(Animation animation) {
// TODO Auto-generated method stub
}
public void onAnimationEnd(Animation animation) {
child.setPressed(true);
iv.startAnimation(fadeIn());
}
});
iv.clearAnimation();
iv.startAnimation(anim);