繁体   English   中英

android 4.4(kitkat)及以上版本的listview问题

[英]listview issue from android version 4.4(kitkat) and above android version

我正在开发聊天应用程序。我在listview奇怪行为中面临问题。 我的代码在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无关的所有内容都必须设置和取消设置,无论convertView是否为null 您应该首先在if-else 之后移动与viewHolder绑定无关的代码。
另一个选择是开始使用RecyclerView ,它本质上类似于ListView ,它的回收机制得到了改进(还有很多)。 这是一个指南

无论是新视图还是回收的视图,都需要为所有视图执行一些代码。 仅对于新视图,将只执行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)。 一个起点就是这个

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

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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