简体   繁体   中英

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

I am developing chat application.i am facing issue in listview odd behavior. My code is working perfectly below android OS 4.4 . but when running my application in 4.4 kitkat then i am facing issue.

please check below Screenshots. 文字被剪掉多余的空间。

Suppose my First message length is large then my Second message height get same.

In Second Screenshot it will show proper view of last message. Because i have close my keyboard and adapter get refresh at the same time first visible view height gets increase automatically.

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 inflater Layout

<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));
        }
    }

Because of the behaviour of view recycling, everything that has to do with content has to be set and un-set regardless if convertView is null or not. You should start by moving the code that has nothing to do with viewHolder binding to after the if-else.
Another option would be to start using RecyclerView which is esentially like ListView that has the recycling mechanism improved (and a lot more). Here is a guide for that.

There are pieces of code you need to execute for all the views, regardless of them being new or recycled. Only the viewholder init part is to be executed only for new views.

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);

Also, you should really consider reading more about having different view types in an adaptor (myLayout and otherLayout in your case). A starting point would be 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);
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM