HI all,我在listView中监听onTouch事件,当事件发生时对焦点所在列表项进行动画操作,运行结果:焦点所在的列表项按我的想法显示了结果,但是奇怪的是,与焦点所在的列表项相差6的没有显示的列表项也产生了动画效果,这是为什么呢

解决方案 »

  1.   

    关键代码,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;
    }
    }