重绘布局导致覆盖其子android

时间:2015-04-26 14:25:08

标签: android layout view drawing

我再次重新绘制布局时遇到了问题,首先我得到了评论列表,然后将其添加到带有inflate的布局中,但是当我需要在评论列表中添加评论时,我尝试从父布局中删除所有视图并再次添加,我的问题是,当我再次重新绘制布局时,它会覆盖旧视图

int counter_add_tolayout= 0;

private void InitializeLayoutComments(CommentModel commentModel) {
    // TODO Auto-generated method stub
    final View layout = LayoutInflater.from(this).inflate(
            R.layout.item_comment_list,
            layout_commentsList_container_PostActivity, false);
    layout.setTag("" + counter_add_tolayout);
    counter_add_tolayout++;
    ProgressBar progressprofilepic_commentitem = (ProgressBar) layout
            .findViewById(R.id.progressprofilepic_commentitem);
    ImageView imgview_profilepic_commentitem = (ImageView) layout
            .findViewById(R.id.imgview_profilepic_commentitem);
    TextView txtview_commentusername_commentitem = (TextView) layout
            .findViewById(R.id.txtview_commentusername_commentitem);
    TextView txtview_commentTime_commentitem = (TextView) layout
            .findViewById(R.id.txtview_commentTime_commentitem);
    TextView txtview_commentbody_commentitem = (TextView) layout
            .findViewById(R.id.txtview_commentbody_commentitem);
    String uri = "http://newcairo.net/photos/small-"
            + commentModel.getCuserid() + ".jpg";
    Load_Picture(imgview_profilepic_commentitem, uri,
            progressprofilepic_commentitem);
    txtview_commentusername_commentitem
            .setText(commentModel.getCusername());
    txtview_commentbody_commentitem.setText(commentModel.getComment());

    if (commentModel.getComment_Status().equals(CommonUtilities.UPLOADING)) {
        InitAnimation(.5f);
        layout.startAnimation(alfaAnimation);
        txtview_commentTime_commentitem
                .setText(CommonUtilities.UPLOADING);
        int position = Integer
                .parseInt(layout.getTag().toString());
        new AddCommentWebTask(position, commentModel,
                commentModel.getUploading_status()).execute();
    } else {
        InitAnimation(1);
        layout.startAnimation(alfaAnimation);
        String commentTime = CommonUtilities
                .getRelativeTimeSpanString(commentModel.getCommentdate());
        txtview_commentTime_commentitem.setText(commentTime);
    }


    imgview_profilepic_commentitem
            .setOnClickListener(new OnClickListener() {

                @Override
                public void onClick(View v) {
                    // TODO Auto-generated method stub
                    int position = Integer
                            .parseInt(layout.getTag().toString());
                    Intent intent = new Intent(getApplicationContext(),
                            OtherUsersProfileActivity.class);
                    intent.putExtra("name", comments.get(position)
                            .getCusername());
                    intent.putExtra("id", comments.get(position).getCuserid());
                    startActivity(intent);
                }
            });
    txtview_commentusername_commentitem
            .setOnClickListener(new OnClickListener() {

                @Override
                public void onClick(View v) {
                    // TODO Auto-generated method stub
                    int index = Integer
                            .parseInt(layout.getTag().toString());
                    Intent intent = new Intent(getApplicationContext(),
                            OtherUsersProfileActivity.class);
                    intent.putExtra("name", comments.get(index)
                            .getCusername());
                    intent.putExtra("id", comments.get(index).getCuserid());
                    startActivity(intent);
                }
            });
    layout.setOnLongClickListener(new OnLongClickListener() {

        @Override
        public boolean onLongClick(View v) {
            // TODO Auto-generated method stub
            return false;
        }
    });
    layout.invalidate();
    layout_commentsList_container_PostActivity.invalidate();
    layout_commentsList_container_PostActivity.addView(layout);
    layout_commentsList_container_PostActivity.invalidate();    
    findViewById(android.R.id.content).invalidate();
}

我试试

findViewById(android.R.id.content).invalidate();
layout.invalidate();
layout_commentsList_container_PostActivity.invalidate();

但没有变化

请参阅此图片并提供帮助 enter image description here

0 个答案:

没有答案