android 版本 4.4(kitkat) 及更高 android 版本的列表视图问题

listview issue from android version 4.4(kitkat) and above android version

我正在开发聊天 application.i 我在列表视图中遇到奇怪行为的问题。 我的代码在 android OS 4.4 下运行完美。但是当 运行 我在 4.4 kitkat 中的应用程序时,我遇到了问题。

请查看下面的截图。

假设我的第一条消息长度很大,那么我的第二条消息高度相同。

在第二个屏幕截图中,它将显示最后一条消息的正确视图。因为我关闭了我的键盘和适配器同时刷新第一个可见视图高度自动增加。

public class ChatAdapter extends BaseAdapter {

    LayoutInflater mInflater;
    ChatActivity chatActivity;
    private DatabaseHandler DatabaseHandler;
    private DatabaseHandler dbHelper;
    private List<HBMessage> mList = new ArrayList<HBMessage>();
    private Context mContext;

    public ChatAdapter(ChatActivity chatActivity) {
        this.chatActivity = chatActivity;
        mContext = chatActivity;
        DatabaseHandler = new DatabaseHandler(mContext);
        dbHelper = new DatabaseHandler(mContext);
    }

    @Override
    public int getCount() {

        return mList.size();
    }

    @Override
    public HBMessage getItem(int position) {
        return mList.get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    private class Holder {

        private RelativeLayout mSimpleRecieveLayout, mSimpleSenderLayout, rlImageSendLayout, rlImageReceiveLayout, mRecieveImageLayout;
        private LinearLayout mSentImageLayout;
        private TextView simpleFriendMessage, simpleFriendMessageTime, simpleMyMessage, simpleMyMessageTime, mtxtImageSentTime,
                mtxtImageRecieveTime;
        private ImageView mimgSent, mimgRecieve, mplayordownload, mplayorupload;
        private TextView mMsgStatus, mtxtImageStatus;
        private ProgressBar mSentProgress, mDownloadProgress;
    }

    @SuppressLint("InflateParams")
    @Override
    public View getView(int position, View convertView, ViewGroup parent) {

        final Holder mHolder;
        if (convertView == null) {
            mHolder = new Holder();
            mInflater = (LayoutInflater) mContext.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
            convertView = mInflater.inflate(R.layout.single_chat_item, null);

            mHolder.mSimpleRecieveLayout = (RelativeLayout) convertView.findViewById(R.id.recive_layout);

            mHolder.mSimpleSenderLayout = (RelativeLayout) convertView.findViewById(R.id.sender_layout);
            mHolder.mSentImageLayout = (LinearLayout) convertView.findViewById(R.id.sentImageLayout);
            mHolder.mRecieveImageLayout = (RelativeLayout) convertView.findViewById(R.id.recieveImageLayout);

            mHolder.simpleFriendMessage = (TextView) convertView.findViewById(R.id.txtMesssageSender);
            mHolder.simpleFriendMessageTime = (TextView) convertView.findViewById(R.id.txtTimeSender);
            mHolder.mtxtImageRecieveTime = (TextView) convertView.findViewById(R.id.txtImageRecieveTime);

            mHolder.simpleMyMessage = (TextView) convertView.findViewById(R.id.txtMesssageRecieve);
            mHolder.simpleMyMessageTime = (TextView) convertView.findViewById(R.id.txtTimeRecieve);
            mHolder.mtxtImageSentTime = (TextView) convertView.findViewById(R.id.txtImageSentTime);

            mHolder.mMsgStatus = (TextView) convertView.findViewById(R.id.txtStatusSender);
            mHolder.mtxtImageStatus = (TextView) convertView.findViewById(R.id.txtImageSentStatus);

            mHolder.mimgSent = (ImageView) convertView.findViewById(R.id.imgSent);
            mHolder.mimgRecieve = (ImageView) convertView.findViewById(R.id.imgRecieve);
            mHolder.mSentProgress = (ProgressBar) convertView.findViewById(R.id.sentProgress);
            mHolder.mplayordownload = (ImageView) convertView.findViewById(R.id.playordownload);
            mHolder.mplayorupload = (ImageView) convertView.findViewById(R.id.playorupload);
            mHolder.mDownloadProgress = (ProgressBar) convertView.findViewById(R.id.downloadProgress);

            mHolder.rlImageSendLayout = (RelativeLayout) convertView.findViewById(R.id.chat_rlSendImage);
            mHolder.rlImageReceiveLayout = (RelativeLayout) convertView.findViewById(R.id.chat_rlReceiveImage);

            int tempWidth = (int) (BaseApplication.SCREEN_WIDTH * 0.28);
            int tempHeight = (int) (BaseApplication.SCREEN_WIDTH * 0.26);

            int imageSize = (int) (tempHeight * 0.84);

            LinearLayout.LayoutParams param1 = (LayoutParams) mHolder.rlImageSendLayout.getLayoutParams();
            param1.width = tempWidth;
            param1.height = tempHeight;
            mHolder.rlImageSendLayout.setLayoutParams(param1);

            RelativeLayout.LayoutParams param2 = (android.widget.RelativeLayout.LayoutParams) mHolder.rlImageReceiveLayout
                    .getLayoutParams();
            param2.width = tempWidth;
            param2.height = tempHeight;
            mHolder.rlImageReceiveLayout.setLayoutParams(param2);

            RelativeLayout.LayoutParams param3 = (android.widget.RelativeLayout.LayoutParams) mHolder.mimgSent.getLayoutParams();
            param3.width = imageSize;
            param3.height = imageSize;
            mHolder.mimgSent.setLayoutParams(param3);

            RelativeLayout.LayoutParams param4 = (android.widget.RelativeLayout.LayoutParams) mHolder.mimgRecieve.getLayoutParams();
            param4.width = imageSize;
            param4.height = imageSize;
            mHolder.mimgRecieve.setLayoutParams(param4);

            convertView.setTag(mHolder);
        } else {
            mHolder = (Holder) convertView.getTag();
        }
        if ((mList.get(position).getFromJID().equalsIgnoreCase(UserDetails.getInstance(mContext).getJabberId() + WSUtils.CHAT_DOMAIN))) {

            setMyLayout(mList.get(position), mHolder, position, convertView);

        } else {

            setOtherLayout(mList.get(position), mHolder, position);

        }

        return convertView;

    }

XML 充气机布局

<RelativeLayout
    android:id="@+id/sender_layout"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:gravity="end"
    android:clickable="false"
    android:visibility="visible" >

    <LinearLayout
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_gravity="end"
        android:background="@drawable/chat_sender"
        android:orientation="vertical" >

        <com.hb.utils.CustomTextView
            android:id="@+id/txtMesssageSender"
            android:layout_width="match_parent"
            android:layout_height="0dp"
            android:layout_marginLeft="@dimen/chatpadding"
            android:layout_marginRight="@dimen/chatpadding"
            android:layout_weight="1"
            android:gravity="center_vertical"
            android:textAppearance="?android:attr/textAppearanceSmall"
            android:textColor="@color/color_text"
            android:textSize="@dimen/chattext"
            app:type="common" />

        <com.hb.utils.CustomTextView
            android:id="@+id/txtTimeSender"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_gravity="end"
            android:layout_marginBottom="@dimen/chat_nagetive_pad"
            android:layout_marginRight="@dimen/chatpadding"
            android:layout_marginEnd="@dimen/chatpadding"
            android:layout_marginTop="2dp"
            android:textColor="@color/graychars"
            android:textSize="@dimen/chattime"
            app:type="common" />

        <com.hb.utils.CustomTextView
            android:id="@+id/txtStatusSender"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_gravity="end"
            android:layout_marginRight="@dimen/chatpadding"
            android:layout_marginEnd="@dimen/chatpadding"
            android:requiresFadingEdge="vertical"
            android:textColor="@color/color_regular_green"
            android:textSize="@dimen/chattime"
            app:type="common" />
    </LinearLayout>
</RelativeLayout>

<RelativeLayout
    android:id="@+id/recive_layout"
    android:layout_width="match_parent"
    android:layout_height="wrap_content" >

    <LinearLayout
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:background="@drawable/chat_receiver"
        android:orientation="vertical" >

        <com.hb.utils.CustomTextView
            android:id="@+id/txtMesssageRecieve"
            android:layout_width="match_parent"
            android:layout_height="0dp"
            android:layout_marginLeft="@dimen/chatpadding"
            android:layout_marginRight="@dimen/chatpadding"
            android:layout_weight="1"
            android:gravity="center_vertical"
            android:textAppearance="?android:attr/textAppearanceSmall"
            android:textColor="@color/color_text"
            android:textSize="@dimen/chattext"
            app:type="common" />

        <com.hb.utils.CustomTextView
            android:id="@+id/txtTimeRecieve"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_gravity="end"
            android:layout_marginRight="@dimen/chatpadding"
            android:layout_marginEnd="@dimen/chatpadding"
            android:layout_marginTop="2dp"
            android:requiresFadingEdge="vertical"
            android:textColor="@color/graychars"
            android:textSize="@dimen/chattime"
            app:type="common" />
    </LinearLayout>
</RelativeLayout>

<LinearLayout
    android:id="@+id/sentImageLayout"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:orientation="vertical" >

    <RelativeLayout
        android:id="@+id/chat_rlSendImage"
        android:layout_width="210px"
        android:layout_height="210px"
        android:layout_gravity="end"
        android:background="@drawable/chat_sender"
        android:gravity="end|center_vertical" >

        <RelativeLayout
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:padding="@dimen/chatpadding" >

            <ImageView
                android:id="@+id/imgSent"
                android:layout_width="match_parent"
                android:layout_height="match_parent"
                android:contentDescription="@string/app_name"
                android:scaleType="centerCrop"
                android:src="@drawable/noimage" />

            <ProgressBar
                android:id="@+id/sentProgress"
                style="?android:attr/progressBarStyleInverse"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_centerInParent="true"
                android:visibility="visible" />

            <ImageView
                android:id="@+id/playorupload"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_centerInParent="true"
                android:src="@drawable/upload"
                android:visibility="gone" />
        </RelativeLayout>
    </RelativeLayout>

    <com.hb.utils.CustomTextView
        android:id="@+id/txtImageSentTime"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_gravity="end"
        android:layout_marginBottom="@dimen/chat_nagetive_pad"
        android:layout_marginRight="@dimen/chatimagetext"
        android:layout_marginEnd="@dimen/chatimagetext"
        android:layout_marginTop="2dp"
        android:textColor="@color/graychars"
        android:textSize="@dimen/chattime"
        app:type="common" />

    <com.hb.utils.CustomTextView
        android:id="@+id/txtImageSentStatus"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_gravity="end"
        android:layout_marginRight="@dimen/chatimagetext"
        android:layout_marginEnd="@dimen/chatimagetext"
        android:textColor="@color/color_regular_green"
        android:textSize="@dimen/chattime"
        app:type="common" />
</LinearLayout>

<RelativeLayout
    android:id="@+id/recieveImageLayout"
    android:layout_width="match_parent"
    android:layout_height="wrap_content" >

    <RelativeLayout
        android:id="@+id/chat_rlReceiveImage"
        android:layout_width="210px"
        android:layout_height="210px"
        android:background="@drawable/chat_receiver"
        android:gravity="center_vertical" >

        <RelativeLayout
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:padding="@dimen/chatpadding" >

            <ImageView
                android:id="@+id/imgRecieve"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:contentDescription="@string/app_name"
                android:scaleType="centerCrop"
                android:src="@drawable/noimage" />

            <ProgressBar
                android:id="@+id/downloadProgress"
                style="?android:attr/progressBarStyleInverse"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_centerInParent="true"
                android:visibility="gone" />

            <ImageView
                android:id="@+id/playordownload"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_centerInParent="true"
                android:src="@drawable/download" />
        </RelativeLayout>
    </RelativeLayout>

    <com.hb.utils.CustomTextView
        android:id="@+id/txtImageRecieveTime"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignRight="@id/chat_rlReceiveImage"
        android:layout_alignEnd="@id/chat_rlReceiveImage"
        android:layout_below="@id/chat_rlReceiveImage"
        android:textColor="@color/graychars"
        android:textSize="@dimen/chattime"
        app:type="common" />
</RelativeLayout>

private synchronized void setOtherLayout(HBMessage hbMessage, final Holder mHolder, final int position) {
        if (hbMessage.getMsgType().equalsIgnoreCase(HBMessage.IMAGE)) {
            mHolder.mSimpleRecieveLayout.setVisibility(View.GONE);
            mHolder.mSimpleSenderLayout.setVisibility(View.GONE);
            mHolder.mSentImageLayout.setVisibility(View.GONE);
            mHolder.mRecieveImageLayout.setVisibility(View.VISIBLE);

            mHolder.mplayordownload.setTag(position);
            mHolder.mimgRecieve.setTag(position);

            String str = hbMessage.getMessage();
            final String seperatedString[] = str.split("##@!@##");

            if (hbMessage.getMediaStatus().equals(HBMessage.NOTDOWNLOADED)) {
                mHolder.mplayordownload.setVisibility(View.VISIBLE);
                mHolder.mDownloadProgress.setVisibility(View.GONE);
            } else if (hbMessage.getMediaStatus().equals(HBMessage.DOWNLOADING)) {
                mHolder.mplayordownload.setVisibility(View.GONE);
                mHolder.mDownloadProgress.setVisibility(View.VISIBLE);
            } else {

                mHolder.mplayordownload.setVisibility(View.GONE);
                mHolder.mDownloadProgress.setVisibility(View.GONE);
            }

            mHolder.mtxtImageRecieveTime.setText(StaticUtils.getChatHistoryDateTime(hbMessage.getMessageTime()));
            chatActivity.runOnUiThread(new Runnable() {

                @Override
                public void run() {
                    mHolder.mimgRecieve.setImageBitmap(getImageFromBase64StringWithTimeStamp(seperatedString[0]));
                }
            });

            mHolder.mplayordownload.setOnClickListener(new OnClickListener() {

                @Override
                public void onClick(View paramView) {
                    paramView.setVisibility(View.GONE);
                    int pos = (Integer) paramView.getTag();
                    HBMessage message = getItem(pos);
                    final String name[] = message.getMessage().split("##@!@##");
                    if (dbHelper.isImageAvaialble(name[1])) {

                        DatabaseHandler.updateImageStatus(mContext, message.getMessageId(), HBMessage.DOWNLOADED, HBMessage.CHAT_SINGLE);
                        message.setMediaStatus(HBMessage.DOWNLOADED);
                        setItem(message, pos);
                    } else {
                        ((ViewGroup) paramView.getParent()).findViewById(R.id.downloadProgress).setVisibility(View.VISIBLE);
                        message.setMediaStatus(HBMessage.DOWNLOADING);
                        setItem(message, position);
                        chatActivity.callDownloadfileProcess(pos, ((ViewGroup) paramView.getParent()));
                    }
                }
            });

        } else {

            mHolder.mSimpleRecieveLayout.setVisibility(View.VISIBLE);
            mHolder.mSimpleSenderLayout.setVisibility(View.GONE);
            mHolder.mSentImageLayout.setVisibility(View.GONE);
            mHolder.mRecieveImageLayout.setVisibility(View.GONE);

            mHolder.simpleMyMessageTime.setText(StaticUtils.getChatHistoryDateTime(hbMessage.getMessageTime()));
            mHolder.simpleMyMessage.setText(hbMessage.getMessage());
        }
    }

    private synchronized void setMyLayout(HBMessage hbMessage, final Holder mHolder, int position, View view) {

        if (hbMessage.getMsgType().equalsIgnoreCase(HBMessage.IMAGE)) {

            mHolder.mSimpleRecieveLayout.setVisibility(View.GONE);
            mHolder.mSimpleSenderLayout.setVisibility(View.GONE);
            mHolder.mRecieveImageLayout.setVisibility(View.GONE);
            mHolder.mSentImageLayout.setVisibility(View.VISIBLE);

            String str = hbMessage.getMessage();
            final String seperatedString[] = str.split("##@!@##");

            mHolder.mimgSent.setTag(position);
            mHolder.mplayorupload.setTag(position);

            if (hbMessage.getMediaStatus().equals(HBMessage.NOTUPLOADED)) {
                mHolder.mplayorupload.setVisibility(View.VISIBLE);
                mHolder.mSentProgress.setVisibility(View.GONE);
            } else if (hbMessage.getMediaStatus().equals(HBMessage.UPLOADING)) {
                mHolder.mplayorupload.setVisibility(View.GONE);
                mHolder.mSentProgress.setVisibility(View.VISIBLE);
            } else {
                mHolder.mplayorupload.setVisibility(View.GONE);
                mHolder.mSentProgress.setVisibility(View.GONE);
            }
            mHolder.mSentProgress.setTag(view);
            mHolder.mtxtImageSentTime.setText(StaticUtils.getChatHistoryDateTime(hbMessage.getMessageTime()));

            chatActivity.runOnUiThread(new Runnable() {

                @Override
                public void run() {
                    mHolder.mimgSent.setImageBitmap(getImageFromBase64StringWithTimeStamp(seperatedString[0]));
                }
            });

            mHolder.mtxtImageStatus.setText(hbMessage.getMessageStatus());
            if (hbMessage.getMessageStatus().equals(HBMessage.STATUS_PENDDING)
                    || hbMessage.getMessageStatus().equals(HBMessage.STATUS_FAILED)) {
                mHolder.mtxtImageStatus.setTextColor(mContext.getResources().getColor(R.color.color_pending_red));
            } else if (hbMessage.getMessageStatus().equals(HBMessage.STATUS_DELIVERED)) {
                mHolder.mtxtImageStatus.setTextColor(mContext.getResources().getColor(R.color.color_black));
            } else
                mHolder.mtxtImageStatus.setTextColor(mContext.getResources().getColor(R.color.color_green));

            if (hbMessage.isAutoUpload()) {
                ImageHolder mImageHolder = dbHelper.getImageHolder(seperatedString[1]);
                File mFile = StaticUtils.bitmapToFile(mImageHolder.getBitmap(), mImageHolder.getFileName(), false);
                if (mFile != null) {
                    hbMessage.setAutoUpload(false);
                    mList.set(position, hbMessage);
                    chatActivity.uploadToserver(mFile, mImageHolder.getFileName(), hbMessage, position, view);
                } else {
                    CommonUtils.showSingleBtnDialog("Image Not Available", mContext, null);
                }
            }

            mHolder.mplayorupload.setOnClickListener(new OnClickListener() {

                @Override
                public void onClick(View paramView) {
                    int pos = (Integer) paramView.getTag();

                    HBMessage message = getItem(pos);
                    final String seperatedString[] = message.getMessage().split("##@!@##");
                    ImageHolder mImageHolder = dbHelper.getImageHolder(seperatedString[1]);
                    File mFile = StaticUtils.bitmapToFile(mImageHolder.getBitmap(), mImageHolder.getFileName(), false);
                    if (mFile != null) {
                        paramView.setVisibility(View.GONE);
                        ProgressBar pb = (ProgressBar) ((ViewGroup) paramView.getParent()).findViewById(R.id.sentProgress);
                        pb.setVisibility(View.VISIBLE);
                        View view = (View) pb.getTag();
                        ((TextView) view.findViewById(R.id.txtImageSentStatus)).setText(HBMessage.STATUS_PENDDING);

                        message.setMediaStatus(HBMessage.UPLOADING);
                        message.setMessageStatus(HBMessage.STATUS_PENDDING);
                        setItem(message, pos);

                        chatActivity.uploadToserver(mFile, mFile.getName(), message, pos, view);
                        DatabaseHandler.updateImageStatus(mContext, message.getMessageId(), HBMessage.UPLOADING, HBMessage.CHAT_SINGLE);
                    } else {
                        CommonUtils.showSingleBtnDialog("Image Not Available", mContext, null);
                    }

                }
            });

        } else {
            mHolder.mSimpleRecieveLayout.setVisibility(View.GONE);
            mHolder.mSimpleSenderLayout.setVisibility(View.VISIBLE);
            mHolder.mSentImageLayout.setVisibility(View.GONE);
            mHolder.mRecieveImageLayout.setVisibility(View.GONE);

            mHolder.simpleFriendMessageTime.setText(StaticUtils.getChatHistoryDateTime(hbMessage.getMessageTime()));
            mHolder.simpleFriendMessage.setText(hbMessage.getMessage());

            mHolder.mMsgStatus.setText(hbMessage.getMessageStatus());
            if (hbMessage.getMessageStatus().equals(HBMessage.STATUS_PENDDING)
                    || hbMessage.getMessageStatus().equals(HBMessage.STATUS_FAILED)) {
                mHolder.mMsgStatus.setTextColor(mContext.getResources().getColor(R.color.color_pending_red));
            } else if (hbMessage.getMessageStatus().equals(HBMessage.STATUS_DELIVERED)) {
                mHolder.mMsgStatus.setTextColor(mContext.getResources().getColor(R.color.color_black));
            } else
                mHolder.mMsgStatus.setTextColor(mContext.getResources().getColor(R.color.color_green));
        }
    }

由于视图回收的行为,与内容有关的所有内容 都必须设置和取消设置,无论 convertView 是否为 null 或不。您应该首先将与 viewHolder 绑定无关的代码移动到 after the if-else.
另一种选择是为此开始使用 RecyclerView which is esentially like ListView that has the recycling mechanism improved (and a lot more). Here is a guide

您需要为所有视图执行一些代码,无论它们是新的还是回收的。只有 viewholder init 部分只对新视图执行。

if (convertView == null) {
    mHolder = new Holder();
    mInflater = (LayoutInflater) mContext.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
    convertView = mInflater.inflate(R.layout.single_chat_item, null);

    mHolder.mSimpleRecieveLayout = (RelativeLayout) convertView.findViewById(R.id.recive_layout);

    mHolder.mSimpleSenderLayout = (RelativeLayout) convertView.findViewById(R.id.sender_layout);
    mHolder.mSentImageLayout = (LinearLayout) convertView.findViewById(R.id.sentImageLayout);
    mHolder.mRecieveImageLayout = (RelativeLayout) convertView.findViewById(R.id.recieveImageLayout);

    mHolder.simpleFriendMessage = (TextView) convertView.findViewById(R.id.txtMesssageSender);
    mHolder.simpleFriendMessageTime = (TextView) convertView.findViewById(R.id.txtTimeSender);
    mHolder.mtxtImageRecieveTime = (TextView) convertView.findViewById(R.id.txtImageRecieveTime);

    mHolder.simpleMyMessage = (TextView) convertView.findViewById(R.id.txtMesssageRecieve);
    mHolder.simpleMyMessageTime = (TextView) convertView.findViewById(R.id.txtTimeRecieve);
    mHolder.mtxtImageSentTime = (TextView) convertView.findViewById(R.id.txtImageSentTime);

    mHolder.mMsgStatus = (TextView) convertView.findViewById(R.id.txtStatusSender);
    mHolder.mtxtImageStatus = (TextView) convertView.findViewById(R.id.txtImageSentStatus);

    mHolder.mimgSent = (ImageView) convertView.findViewById(R.id.imgSent);
    mHolder.mimgRecieve = (ImageView) convertView.findViewById(R.id.imgRecieve);
    mHolder.mSentProgress = (ProgressBar) convertView.findViewById(R.id.sentProgress);
    mHolder.mplayordownload = (ImageView) convertView.findViewById(R.id.playordownload);
    mHolder.mplayorupload = (ImageView) convertView.findViewById(R.id.playorupload);
    mHolder.mDownloadProgress = (ProgressBar) convertView.findViewById(R.id.downloadProgress);

    mHolder.rlImageSendLayout = (RelativeLayout) convertView.findViewById(R.id.chat_rlSendImage);
    mHolder.rlImageReceiveLayout = (RelativeLayout) convertView.findViewById(R.id.chat_rlReceiveImage);
    convertView.setTag(mHolder);
} else {
    mHolder = (Holder) convertView.getTag();
} 
    // This is now executed for all your views.
    int tempWidth = (int) (BaseApplication.SCREEN_WIDTH * 0.28);
    int tempHeight = (int) (BaseApplication.SCREEN_WIDTH * 0.26);

    int imageSize = (int) (tempHeight * 0.84);

    LinearLayout.LayoutParams param1 = (LayoutParams) mHolder.rlImageSendLayout.getLayoutParams();
    param1.width = tempWidth;
    param1.height = tempHeight;
    mHolder.rlImageSendLayout.setLayoutParams(param1);

    RelativeLayout.LayoutParams param2 = (android.widget.RelativeLayout.LayoutParams) mHolder.rlImageReceiveLayout
            .getLayoutParams();
    param2.width = tempWidth;
    param2.height = tempHeight;
    mHolder.rlImageReceiveLayout.setLayoutParams(param2);

    RelativeLayout.LayoutParams param3 = (android.widget.RelativeLayout.LayoutParams) mHolder.mimgSent.getLayoutParams();
    param3.width = imageSize;
    param3.height = imageSize;
    mHolder.mimgSent.setLayoutParams(param3);

    RelativeLayout.LayoutParams param4 = (android.widget.RelativeLayout.LayoutParams) mHolder.mimgRecieve.getLayoutParams();
    param4.width = imageSize;
    param4.height = imageSize;
    mHolder.mimgRecieve.setLayoutParams(param4);

此外,您真的应该考虑阅读更多有关在适配器中使用不同视图类型(在您的情况下为 myLayout 和 otherLayout)的信息。起点是 this.

Finally I have solved this issue by applying stupid thing.Why i am facing issue,that i really don't know and Why its get solved after applying patch that i really don't know.

**My Solution:**

    setMyLayout()
{
    mHolder.mSentMessageLayout
                        .setBackgroundResource(R.drawable.chat_sender);
}    
    setOtherLayout()
{
    mHolder.mRecieveMessageLayout
                        .setBackgroundResource(R.drawable.chat_receiver);
}