ListView中诡异的问题。大家帮帮忙,谢谢啦。 HI all,我在listView中监听onTouch事件,当事件发生时对焦点所在列表项进行动画操作,运行结果:焦点所在的列表项按我的想法显示了结果,但是奇怪的是,与焦点所在的列表项相差6的没有显示的列表项也产生了动画效果,这是为什么呢 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 关键代码,onTouch事件: private void postListAnimation(int aPos, ListView aLv) { Log.i("Life==", "goto_postListAnimation_"+String.valueOf(aPos)); int firstVisiblePosition = aLv.getFirstVisiblePosition(); RelativeLayout nRelative = (RelativeLayout) aLv.getChildAt(aPos - firstVisiblePosition); PostItemView nPview=(PostItemView)nRelative.getTag(); if (nRelative != null) { LinearLayout nDoLinear = nPview.mLinear; if (nDoLinear == null) return; boolean nShow = false; if (nDoLinear.getVisibility() == View.GONE) nShow = true; RelativeLayout.LayoutParams nLp = (RelativeLayout.LayoutParams) nDoLinear .getLayoutParams(); LinearLayout nInfoLinear = nPview.mLinearInfo;// .findViewById(R.id.linear_info); if (nInfoLinear == null) return; nLp.height = nInfoLinear.getHeight(); nDoLinear.setLayoutParams(nLp); float nDoSx = -1.0f, nDoMx = 0.0f, nInfoSx = 0.0f, nInfoMx = 0.45f; if (!nShow) { nInfoSx = 0.45f; nInfoMx = 0.0f; nDoSx = 0.0f; nDoMx = -1.0f; } TranslateAnimation nDoLinearTa = new TranslateAnimation( Animation.RELATIVE_TO_SELF, nDoSx, Animation.RELATIVE_TO_SELF, nDoMx, Animation.RELATIVE_TO_SELF, 0.0f, Animation.RELATIVE_TO_SELF, 0.0f); nDoLinearTa.setDuration(150); nDoLinearTa.setFillAfter(true); /* * Button nBtnApp=(Button)nDoLinear.findViewById(R.id.btn_app); * Button nBtnCol=(Button)nDoLinear.findViewById(R.id.btn_col); */ TranslateAnimation nInfoLinearTa = new TranslateAnimation( Animation.RELATIVE_TO_SELF, nInfoSx, Animation.RELATIVE_TO_SELF, nInfoMx, Animation.RELATIVE_TO_SELF, 0.0f, Animation.RELATIVE_TO_SELF, 0.0f); nInfoLinearTa.setDuration(150); nInfoLinearTa.setFillAfter(true); if (mLastLinear != null) mLastLinear.clearAnimation(); if (mLastDoLinear != null) { mLastDoLinear.setVisibility(View.GONE); mLastDoLinear.clearAnimation(); } if (nShow) { nDoLinear.setVisibility(View.VISIBLE); } else { } mLastLinear = nInfoLinear; mLastDoLinear = nDoLinear; nInfoLinear.startAnimation(nInfoLinearTa); nDoLinear.startAnimation(nDoLinearTa); } }=============================================适配器getView:public View getView(int position, View convertView, ViewGroup parent) { mMark=false; Log.i("Life==", "goto_getView_"+String.valueOf(position)); if (convertView == null){ convertView = mFty.inflate(this.mAdptType, null); mMark=true; } switch (this.mAdptType) { case R.layout.postitemlist: { PostItemView nPv; PostNode nNode = (PostNode) this.mAdpt.get(position); if (convertView.getTag() == null) { nPv=new PostItemView(); nPv.mTvName = (TextView) convertView .findViewById(R.id.tv_post); nPv.mTvCpy = (TextView) convertView .findViewById(R.id.tv_cpy); nPv.mTvDate = (TextView) convertView .findViewById(R.id.tv_date); nPv.mTvArea = (TextView) convertView .findViewById(R.id.tv_area); nPv.mBtnApp = (Button) convertView .findViewById(R.id.btn_app); nPv.mBtnCol = (Button) convertView .findViewById(R.id.btn_col); nPv.mLinear=(LinearLayout) convertView .findViewById(R.id.do_layout); nPv.mLinearInfo=(LinearLayout) convertView .findViewById(R.id.linear_info); convertView.setTag(nPv); } else{ nPv=(PostItemView)convertView.getTag(); } nPv.mTvName.setText(nNode.mPname); nPv.mTvCpy.setText(nNode.mPcpy); nPv.mTvDate.setText(nNode.mPdate); nPv.mTvArea.setText(nNode.mParea); nPv.mBtnApp.setTag(String.valueOf(position)); nPv.mBtnApp.setOnClickListener(this.mOnClickListener); nPv.mBtnCol.setTag(String.valueOf(position)); nPv.mBtnCol.setOnClickListener(this.mOnClickListener); break; }} androd 调用系统功能录制视频 时间长度设置无效 android的延时执行问题 android 实现循环呼叫的功能 NDK的cygwin路径配置问题 如何做交互式动画小游戏的程序? android客户端与widget的比较 期待解决Android OpenGL ES显示yuv时 glTexSubImage2D上传数据缓慢的问题 Android Bluetooth 重启后读取不到配对信息 求 phonegap大神解答啊!! 新手求助,写Java里面文件部分的代码遇到问题 最近看到一个android源码 ANDROID_SWT报错
private void postListAnimation(int aPos, ListView aLv) {
Log.i("Life==", "goto_postListAnimation_"+String.valueOf(aPos));
int firstVisiblePosition = aLv.getFirstVisiblePosition();
RelativeLayout nRelative = (RelativeLayout) aLv.getChildAt(aPos
- firstVisiblePosition);
PostItemView nPview=(PostItemView)nRelative.getTag();
if (nRelative != null) {
LinearLayout nDoLinear = nPview.mLinear;
if (nDoLinear == null)
return;
boolean nShow = false;
if (nDoLinear.getVisibility() == View.GONE)
nShow = true;
RelativeLayout.LayoutParams nLp = (RelativeLayout.LayoutParams) nDoLinear
.getLayoutParams();
LinearLayout nInfoLinear = nPview.mLinearInfo;// .findViewById(R.id.linear_info);
if (nInfoLinear == null)
return;
nLp.height = nInfoLinear.getHeight();
nDoLinear.setLayoutParams(nLp);
float nDoSx = -1.0f, nDoMx = 0.0f, nInfoSx = 0.0f, nInfoMx = 0.45f;
if (!nShow) {
nInfoSx = 0.45f;
nInfoMx = 0.0f;
nDoSx = 0.0f;
nDoMx = -1.0f;
} TranslateAnimation nDoLinearTa = new TranslateAnimation(
Animation.RELATIVE_TO_SELF, nDoSx,
Animation.RELATIVE_TO_SELF, nDoMx,
Animation.RELATIVE_TO_SELF, 0.0f,
Animation.RELATIVE_TO_SELF, 0.0f);
nDoLinearTa.setDuration(150);
nDoLinearTa.setFillAfter(true);
/*
* Button nBtnApp=(Button)nDoLinear.findViewById(R.id.btn_app);
* Button nBtnCol=(Button)nDoLinear.findViewById(R.id.btn_col);
*/
TranslateAnimation nInfoLinearTa = new TranslateAnimation(
Animation.RELATIVE_TO_SELF, nInfoSx,
Animation.RELATIVE_TO_SELF, nInfoMx,
Animation.RELATIVE_TO_SELF, 0.0f,
Animation.RELATIVE_TO_SELF, 0.0f);
nInfoLinearTa.setDuration(150);
nInfoLinearTa.setFillAfter(true);
if (mLastLinear != null)
mLastLinear.clearAnimation();
if (mLastDoLinear != null) {
mLastDoLinear.setVisibility(View.GONE);
mLastDoLinear.clearAnimation();
}
if (nShow) {
nDoLinear.setVisibility(View.VISIBLE); } else { }
mLastLinear = nInfoLinear;
mLastDoLinear = nDoLinear;
nInfoLinear.startAnimation(nInfoLinearTa);
nDoLinear.startAnimation(nDoLinearTa);
} }=============================================
适配器getView:
public View getView(int position, View convertView, ViewGroup parent) {
mMark=false;
Log.i("Life==", "goto_getView_"+String.valueOf(position));
if (convertView == null){
convertView = mFty.inflate(this.mAdptType, null);
mMark=true;
}
switch (this.mAdptType) {
case R.layout.postitemlist: {
PostItemView nPv;
PostNode nNode = (PostNode) this.mAdpt.get(position);
if (convertView.getTag() == null) {
nPv=new PostItemView();
nPv.mTvName = (TextView) convertView
.findViewById(R.id.tv_post);
nPv.mTvCpy = (TextView) convertView
.findViewById(R.id.tv_cpy);
nPv.mTvDate = (TextView) convertView
.findViewById(R.id.tv_date);
nPv.mTvArea = (TextView) convertView
.findViewById(R.id.tv_area);
nPv.mBtnApp = (Button) convertView
.findViewById(R.id.btn_app);
nPv.mBtnCol = (Button) convertView
.findViewById(R.id.btn_col);
nPv.mLinear=(LinearLayout) convertView
.findViewById(R.id.do_layout);
nPv.mLinearInfo=(LinearLayout) convertView
.findViewById(R.id.linear_info);
convertView.setTag(nPv);
}
else{
nPv=(PostItemView)convertView.getTag();
}
nPv.mTvName.setText(nNode.mPname);
nPv.mTvCpy.setText(nNode.mPcpy);
nPv.mTvDate.setText(nNode.mPdate);
nPv.mTvArea.setText(nNode.mParea);
nPv.mBtnApp.setTag(String.valueOf(position));
nPv.mBtnApp.setOnClickListener(this.mOnClickListener);
nPv.mBtnCol.setTag(String.valueOf(position));
nPv.mBtnCol.setOnClickListener(this.mOnClickListener);
break;
}
}