RecyclerView 在媒体播放器播放时会滚动。我该如何修复?

huangapple go评论67阅读模式
英文:

Recyclerview is Scrolling when media Player is playing. How can i fix it?

问题

以下是翻译的内容:

我正在开发一个具有音频消息功能的聊天应用程序。这些音频消息的录制和播放功能都运行得很好,但是当我点击播放按钮时,RecyclerView会向上滚动。有人有什么想法吗?

对不起,我的英语不太好,我来自德国 RecyclerView 在媒体播放器播放时会滚动。我该如何修复?

AdapterChat.java

private static final int MSG_TYPE_LEFT = 0;
private static final int MSG_TYPE_RIGHT = 1;
Context context;
List<ModelChat> chatList;
String imageUrl;

FirebaseUser fUser;

public AdapterChat(Context context, List<ModelChat> chatList, String imageUrl) {
    this.context = context;
    this.chatList = chatList;
    this.imageUrl = imageUrl;
}

@NonNull
@Override
public MyHolder onCreateViewHolder(@NonNull ViewGroup viewGroup, int i) {
    //为接收者inflate布局:row_chat_left.xml,为发送者inflate布局:row_chat_right.xml
    if (i == MSG_TYPE_RIGHT) {
        View view = LayoutInflater.from(context).inflate(R.layout.row_chat_right, viewGroup, false);
        return new MyHolder(view);
    } else {
        View view = LayoutInflater.from(context).inflate(R.layout.row_chat_left, viewGroup, false);
        return new MyHolder(view);
    }
}

public void add(ModelChat object) {
    chatList.add(object);
    notifyDataSetChanged();
}

@SuppressLint("ClickableViewAccessibility")
@Override
public void onBindViewHolder(@NonNull final MyHolder myHolder, final int i) {
    final String message = chatList.get(i).getMessage();
    String timeStamp = chatList.get(i).getTimestamp();
    String type = chatList.get(i).getType();

    if (type.equals("text") || message.equals(R.string.message_was_deleted)) {
        //文本消息
        myHolder.messageTv.setVisibility(View.VISIBLE);
        myHolder.messageIv.setVisibility(View.GONE);
        myHolder.playAudioBtn.setVisibility(View.GONE);
        myHolder.messageVoiceSb.setVisibility(View.GONE);
        myHolder.sbCurrentTime.setVisibility(View.GONE);
        myHolder.sbTotalDuration.setVisibility(View.GONE);

        myHolder.messageTv.setText(message);
    } else if (type.equals("audio")) {
        //音频消息
        myHolder.messageTv.setVisibility(View.GONE);
        myHolder.messageIv.setVisibility(View.GONE);
        myHolder.playAudioBtn.setVisibility(View.VISIBLE);
        myHolder.messageVoiceSb.setVisibility(View.VISIBLE);
        myHolder.sbCurrentTime.setVisibility(View.VISIBLE);
        myHolder.sbTotalDuration.setVisibility(View.VISIBLE);

        myHolder.voiceMessageUrl = message;

        myHolder.getAdapterPosition();

        myHolder.playAudioBtn.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                if (myHolder.mediaPlayer.isPlaying()) {
                    myHolder.handler.removeCallbacks(myHolder.updater);
                    myHolder.mediaPlayer.pause();
                    myHolder.playAudioBtn.setImageResource(R.drawable.ic_play_btn);
                } else {
                    myHolder.mediaPlayer.start();
                    myHolder.playAudioBtn.setImageResource(R.drawable.ic_pause_btn);
                    myHolder.updateSeekbar();
                }
            }
        });

        myHolder.prepareMediaPlayer();

        myHolder.messageVoiceSb.setOnTouchListener(new View.OnTouchListener() {
            @Override
            public boolean onTouch(View view, MotionEvent motionEvent) {
                SeekBar seekBar = (SeekBar) view;
                int playPosition = (myHolder.mediaPlayer.getDuration() / 100) * seekBar.getProgress();
                myHolder.mediaPlayer.seekTo(playPosition);
                myHolder.sbCurrentTime.setText(myHolder.milliSecondsToTimer(myHolder.mediaPlayer.getCurrentPosition()));
                return false;
            }
        });

        myHolder.mediaPlayer.setOnBufferingUpdateListener(new MediaPlayer.OnBufferingUpdateListener() {
            @Override
            public void onBufferingUpdate(MediaPlayer mediaPlayer, int i) {
                myHolder.messageVoiceSb.setSecondaryProgress(i);
            }
        });

        myHolder.mediaPlayer.setOnCompletionListener(new MediaPlayer.OnCompletionListener() {
            @Override
            public void onCompletion(MediaPlayer mediaPlayer) {
                myHolder.messageVoiceSb.setProgress(0);
                myHolder.playAudioBtn.setImageResource(R.drawable.ic_play_btn);
                myHolder.mediaPlayer.reset();
                myHolder.prepareMediaPlayer();
            }
        });
    } else {
        //图片消息
        myHolder.messageIv.setVisibility(View.VISIBLE);
        myHolder.messageTv.setVisibility(View.GONE);
        myHolder.playAudioBtn.setVisibility(View.GONE);
        myHolder.messageVoiceSb.setVisibility(View.GONE);
        myHolder.sbCurrentTime.setVisibility(View.GONE);
        myHolder.sbTotalDuration.setVisibility(View.GONE);

        Picasso.get().load(message).placeholder(R.drawable.ic_image_black).into(myHolder.messageIv);
    }

    //设置数据
    myHolder.timeTv.setText(timeStamp);
    try {
        Picasso.get().load(imageUrl).into(myHolder.profileIv);
    } catch (Exception e) {
    }

    myHolder.messageLayout.setOnLongClickListener(new View.OnLongClickListener() {
        @Override
        public boolean onLongClick(View v) {
            //显示删除消息确认对话框
            AlertDialog.Builder builder = new AlertDialog.Builder(context);
            builder.setTitle(R.string.delete);
            builder.setMessage("Are you sure to delete this message?");
            //删除按钮
            builder.setPositiveButton(R.string.delete, new DialogInterface.OnClickListener() {
                @Override
                public void onClick(DialogInterface dialog, int which) {
                    deleteMessage(i);
                }
            });
            //取消删除按钮
            builder.setNegativeButton("No", new DialogInterface.OnClickListener() {
                @Override
                public void onClick(DialogInterface dialog, int which) {
                    //关闭对话框
                    dialog.dismiss();
                }
            });
            //创建并显示对话框
            builder.create().show();
            return false;
        }
    });

    //设置消息的已读/已送达状态
    if (i == chatList.size() - 1) {
        if (chatList.get(i).isSeen()) {
            myHolder.isSeenTv.setText("Seen");
        } else {
            myHolder.isSeenTv.setText("Delivered");
        }
    } else {
        myHolder.isSeenTv.setVisibility(View.GONE);
    }
}

//其它方法和内部类略去...

chatActivity.xml

<!-- 省略其它内容 -->

row_chat_right.xml

<!-- 省略其它内容 -->

请注意,这只是对代码的翻译,我无法保证翻译的准确性。如果您在代码中遇到任何问题,建议您在原始代码上进行调试和检查。

英文:

I'm developing a ChatApp with the function of Audio Messages. The Recording and playing of this Audio Messages are working very well, but if i click on Play Button the Recyclerview is scrolling up. Anyone have an idea?

Sorry for my bad english, i'm from Germany RecyclerView 在媒体播放器播放时会滚动。我该如何修复?

AdapterChat.Java

private static final int MSG_TYPE_LEFT = 0;
private static final int MSG_TYPE_RIGHT = 1;
Context context;
List&lt;ModelChat&gt; chatList;
String imageUrl;
FirebaseUser fUser;
public AdapterChat(Context context, List&lt;ModelChat&gt; chatList, String imageUrl) {
this.context = context;
this.chatList = chatList;
this.imageUrl = imageUrl;
}
@NonNull
@Override
public MyHolder onCreateViewHolder(@NonNull ViewGroup viewGroup, int i) {
//inflate layouts: row_chat_left.xml for receiver, row_chat_right.xml for sender
if (i == MSG_TYPE_RIGHT) {
View view = LayoutInflater.from(context).inflate(R.layout.row_chat_right, viewGroup, false);
return new MyHolder(view);
}
else {
View view = LayoutInflater.from(context).inflate(R.layout.row_chat_left, viewGroup, false);
return new MyHolder(view);
}
}
public void add(ModelChat object) {
chatList.add(object);
add(object);
}
@SuppressLint(&quot;ClickableViewAccessibility&quot;)
@Override
public void onBindViewHolder(@NonNull final MyHolder myHolder, final int i) {
final String message = chatList.get(i).getMessage();
String timeStamp = chatList.get(i).getTimestamp();
String type = chatList.get(i).getType();
if (type.equals(&quot;text&quot;) || message.equals(R.string.message_was_deleted)) {
//text message
myHolder.messageTv.setVisibility(View.VISIBLE);
myHolder.messageIv.setVisibility(View.GONE);
myHolder.playAudioBtn.setVisibility(View.GONE);
myHolder.messageVoiceSb.setVisibility(View.GONE);
myHolder.sbCurrentTime.setVisibility(View.GONE);
myHolder.sbTotalDuration.setVisibility(View.GONE);
myHolder.messageTv.setText(message);
}
else if (type.equals(&quot;audio&quot;)) {
//audio message
myHolder.messageTv.setVisibility(View.GONE);
myHolder.messageIv.setVisibility(View.GONE);
myHolder.playAudioBtn.setVisibility(View.VISIBLE);
myHolder.messageVoiceSb.setVisibility(View.VISIBLE);
myHolder.sbCurrentTime.setVisibility(View.VISIBLE);
myHolder.sbTotalDuration.setVisibility(View.VISIBLE);
myHolder.voiceMessageUrl = message;
myHolder.getAdapterPosition();
myHolder.playAudioBtn.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
if (myHolder.mediaPlayer.isPlaying()) {
myHolder.handler.removeCallbacks(myHolder.updater);
myHolder.mediaPlayer.pause();
myHolder.playAudioBtn.setImageResource(R.drawable.ic_play_btn);
}
else {
myHolder.mediaPlayer.start();
myHolder.playAudioBtn.setImageResource(R.drawable.ic_pause_btn);
myHolder.updateSeekbar();
}
}
});
myHolder.prepareMediaPlayer();
myHolder.messageVoiceSb.setOnTouchListener(new View.OnTouchListener() {
@Override
public boolean onTouch(View view, MotionEvent motionEvent) {
SeekBar seekBar = (SeekBar) view;
int playPosition = (myHolder.mediaPlayer.getDuration() / 100) * seekBar.getProgress();
myHolder.mediaPlayer.seekTo(playPosition);
myHolder.sbCurrentTime.setText(myHolder.milliSecondsToTimer(myHolder.mediaPlayer.getCurrentPosition()));
return false;
}
});
myHolder.mediaPlayer.setOnBufferingUpdateListener(new MediaPlayer.OnBufferingUpdateListener() {
@Override
public void onBufferingUpdate(MediaPlayer mediaPlayer, int i) {
myHolder.messageVoiceSb.setSecondaryProgress(i);
}
});
myHolder.mediaPlayer.setOnCompletionListener(new MediaPlayer.OnCompletionListener() {
@Override
public void onCompletion(MediaPlayer mediaPlayer) {
myHolder.messageVoiceSb.setProgress(0);
myHolder.playAudioBtn.setImageResource(R.drawable.ic_play_btn);
myHolder.mediaPlayer.reset();
myHolder.prepareMediaPlayer();
}
});
}
else {
//image message
myHolder.messageIv.setVisibility(View.VISIBLE);
myHolder.messageTv.setVisibility(View.GONE);
myHolder.playAudioBtn.setVisibility(View.GONE);
myHolder.messageVoiceSb.setVisibility(View.GONE);
myHolder.sbCurrentTime.setVisibility(View.GONE);
myHolder.sbTotalDuration.setVisibility(View.GONE);
Picasso.get().load(message).placeholder(R.drawable.ic_image_black).into(myHolder.messageIv);
}
//set data
myHolder.messageTv.setText(message);
myHolder.timeTv.setText(timeStamp);
try {
Picasso.get().load(imageUrl).into(myHolder.profileIv);
}
catch (Exception e) {
}
myHolder.messageLayout.setOnLongClickListener(new View.OnLongClickListener() {
@Override
public boolean onLongClick(View v) {
//show delete message confirm dialog
AlertDialog.Builder builder = new AlertDialog.Builder(context);
builder.setTitle(R.string.delete);
builder.setMessage(&quot;Are you sure to delete this message?&quot;);
//delete button
builder.setPositiveButton(R.string.delete, new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
deleteMessage(i);
}
});
//cancel delete button
builder.setNegativeButton(&quot;No&quot;, new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
//dismiss dialog
dialog.dismiss();
}
});
//create and show dialog
builder.create().show();
return false;
}
});
//set seen/delivered status of message
if (i==chatList.size()-1) {
if (chatList.get(i).isSeen()) {
myHolder.isSeenTv.setText(&quot;Seen&quot;);
}
else {
myHolder.isSeenTv.setText(&quot;Delivered&quot;);
}
}
else {
myHolder.isSeenTv.setVisibility(View.GONE);
}
}
private void deleteMessage(int position) {
final String myUID = FirebaseAuth.getInstance().getCurrentUser().getUid();
/*Logic:
* Get timeStamp of clicked message
* Compare the timeStamp of the clicked message with all messages in CHats
* Where both values matches, delete that message
* This will allow sender to delete his and receiver&#39;s message*/
String msgTimeStamp = chatList.get(position).getTimestamp();
final String type = chatList.get(position).getType();
DatabaseReference dbRef = FirebaseDatabase.getInstance().getReference(&quot;Chats&quot;);
Query query = dbRef.orderByChild(&quot;timestamp&quot;).equalTo(msgTimeStamp);
query.addListenerForSingleValueEvent(new ValueEventListener() {
@Override
public void onDataChange(@NonNull DataSnapshot dataSnapshot) {
for (DataSnapshot ds: dataSnapshot.getChildren()) {
/*if you want to allow sender to delete only his message then
* compare sender value with current user&#39;s uid
* if they match means its the message of sender that is trying to delete*/
if (ds.child(&quot;sender&quot;).getValue().equals(myUID)) {
if (type.equals(&quot;audio&quot;)) {
HashMap&lt;String, Object&gt; hashMap = new HashMap&lt;&gt;();
hashMap.put(&quot;type&quot;, &quot;text&quot;);
ds.getRef().updateChildren(hashMap);
} else if (type.equals(&quot;image&quot;)) {
HashMap&lt;String, Object&gt; hashMap = new HashMap&lt;&gt;();
hashMap.put(&quot;type&quot;, &quot;text&quot;);
ds.getRef().updateChildren(hashMap);
}
/*We can do one of two things here
* 1) Remove the message from chats
* 2) Set the value of message &quot;This messages was deleted...&quot; */
//1) Remove the message from Chats
//ds.getRef().removeValue();
//2) Set the value of message &quot;This message was deleted...&quot;
HashMap&lt;String, Object&gt; hashMap = new HashMap&lt;&gt;();
hashMap.put(&quot;message&quot;, &quot;This message was deleted...&quot;);
ds.getRef().updateChildren(hashMap);
Toast.makeText(context, &quot;message deleted...&quot;, Toast.LENGTH_SHORT).show();
}
else {
Toast.makeText(context, &quot;You can delete only your messages...&quot;, Toast.LENGTH_SHORT).show();
}
}
}
@Override
public void onCancelled(@NonNull DatabaseError error) {
}
});
}
@Override
public int getItemCount() {
return chatList.size();
}
@Override
public long getItemId(int position) {
return 0;
}
@Override
public int getItemViewType(int position) {
//get currently signed in user
fUser = FirebaseAuth.getInstance().getCurrentUser();
if (chatList.get(position).getSender().equals(fUser.getUid())) {
return MSG_TYPE_RIGHT;
}
else {
return MSG_TYPE_LEFT;
}
}
//view holder class
class MyHolder extends RecyclerView.ViewHolder {
//views
ImageView profileIv, messageIv;
ImageButton playAudioBtn;
SeekBar messageVoiceSb;
TextView messageTv, timeTv, isSeenTv, sbCurrentTime, sbTotalDuration;
LinearLayout messageLayout; //for click listener to show delete option
MediaPlayer mediaPlayer;
Handler handler = new Handler();
String voiceMessageUrl = null;
@SuppressLint(&quot;ClickableViewAccessibility&quot;)
public MyHolder(@NonNull View itemView) {
super(itemView);
//init views
profileIv = itemView.findViewById(R.id.profileIv);
messageIv = itemView.findViewById(R.id.messageIV);
messageTv = itemView.findViewById(R.id.messageTv);
messageVoiceSb = itemView.findViewById(R.id.messageVoiceSb);
playAudioBtn = itemView.findViewById(R.id.playAudioBtn);
sbCurrentTime = itemView.findViewById(R.id.sbCurrentTime);
sbTotalDuration = itemView.findViewById(R.id.sbTotalDuration);
timeTv = itemView.findViewById(R.id.timeTv);
isSeenTv = itemView.findViewById(R.id.isSeenTv);
messageLayout = itemView.findViewById(R.id.messageLayout);
mediaPlayer = new MediaPlayer();
messageVoiceSb.setMax(100);
}
private void prepareMediaPlayer() {
try {
mediaPlayer.setDataSource(voiceMessageUrl); //url of audio file to play
mediaPlayer.prepare();
sbTotalDuration.setText(milliSecondsToTimer(mediaPlayer.getDuration()));
} catch (Exception e) {
Toast.makeText(context, e.getMessage(), Toast.LENGTH_SHORT).show();
}
}
private Runnable updater = new Runnable() {
@Override
public void run() {
updateSeekbar();
long currentDuration = mediaPlayer.getCurrentPosition();
sbCurrentTime.setText(milliSecondsToTimer(currentDuration));
}
};
private void updateSeekbar() {
if (mediaPlayer.isPlaying()) {
messageVoiceSb.setProgress((int) (((float) mediaPlayer.getCurrentPosition() / mediaPlayer.getDuration()) * 100));
handler.postDelayed(updater, 1000);
}
}
private String milliSecondsToTimer(long milliSeconds) {
String timerString = &quot;&quot;;
String secondsString;
int hours = (int) (milliSeconds / (1000 * 60 * 60));
int minutes = (int) (milliSeconds % (1000 * 60 * 60)) / (1000 * 60);
int seconds = (int) ((milliSeconds % (1000 * 60 * 60)) % (1000 * 60) / 1000);
if (hours &gt; 0) {
timerString = hours + &quot;:&quot;;
}
if (seconds &lt; 10) {
secondsString = &quot;0&quot; + seconds;
} else {
secondsString = &quot;&quot; + seconds;
}
timerString = timerString + minutes + &quot;:&quot; + secondsString;
return timerString;
}
}

chatActivity.xml

&lt;RelativeLayout xmlns:android=&quot;http://schemas.android.com/apk/res/android&quot;
xmlns:app=&quot;http://schemas.android.com/apk/res-auto&quot;
xmlns:tools=&quot;http://schemas.android.com/tools&quot;
android:layout_width=&quot;match_parent&quot;
android:layout_height=&quot;match_parent&quot;
android:background=&quot;@color/chatBackground&quot;
tools:context=&quot;.ChatActivity&quot;&gt;
&lt;androidx.appcompat.widget.Toolbar
android:id=&quot;@+id/toolbar&quot;
android:layout_width=&quot;match_parent&quot;
android:layout_height=&quot;?android:attr/actionBarSize&quot;
android:background=&quot;@color/colorPrimaryDark&quot;
android:theme=&quot;@style/ThemeOverlay.AppCompat.Dark.ActionBar&quot;&gt;
&lt;LinearLayout
android:layout_width=&quot;match_parent&quot;
android:layout_height=&quot;wrap_content&quot;
android:orientation=&quot;horizontal&quot;&gt;
&lt;de.hdodenhof.circleimageview.CircleImageView
android:id=&quot;@+id/profileIv&quot;
android:layout_width=&quot;35dp&quot;
android:layout_height=&quot;35dp&quot;
android:scaleType=&quot;centerCrop&quot;
android:src=&quot;@drawable/ic_default&quot;
app:civ_circle_background_color=&quot;@color/colorPrimaryDark&quot;/&gt;
&lt;LinearLayout
android:layout_width=&quot;wrap_content&quot;
android:layout_weight=&quot;1&quot;
android:layout_height=&quot;wrap_content&quot;
android:orientation=&quot;vertical&quot;
android:gravity=&quot;center&quot;
android:layout_marginStart=&quot;20dp&quot;&gt;
&lt;!-- Receiver Name--&gt;
&lt;TextView
android:id=&quot;@+id/nameTv&quot;
android:layout_width=&quot;match_parent&quot;
android:layout_height=&quot;wrap_content&quot;
android:text=&quot;His Name&quot;
android:textColor=&quot;@color/colorWhite&quot;
android:textSize=&quot;18sp&quot;
android:textStyle=&quot;bold&quot; /&gt;
&lt;!-- Receiver Status i.e online or offline--&gt;
&lt;TextView
android:id=&quot;@+id/userStatusTv&quot;
android:layout_width=&quot;match_parent&quot;
android:layout_height=&quot;wrap_content&quot;
android:text=&quot;online&quot;
android:textColor=&quot;@color/colorWhite&quot;
android:textSize=&quot;12sp&quot;
android:textStyle=&quot;bold&quot; /&gt;
&lt;/LinearLayout&gt;
&lt;ImageView
android:id=&quot;@+id/blockIv&quot;
android:layout_gravity=&quot;center_vertical&quot;
android:layout_width=&quot;wrap_content&quot;
android:layout_height=&quot;wrap_content&quot;
android:layout_marginEnd=&quot;5dp&quot;
android:src=&quot;@drawable/ic_unblocked_green&quot;
android:visibility=&quot;invisible&quot;/&gt;
&lt;/LinearLayout&gt;
&lt;/androidx.appcompat.widget.Toolbar&gt;
&lt;!-- RecyclerView--&gt;
&lt;androidx.recyclerview.widget.RecyclerView
android:id=&quot;@+id/chat_recyclerView&quot;
android:layout_width=&quot;match_parent&quot;
android:layout_height=&quot;wrap_content&quot;
android:layout_below=&quot;@id/toolbar&quot;
android:layout_above=&quot;@id/chatLayout&quot; /&gt;
&lt;!-- send message edit text and button in layout--&gt;
&lt;LinearLayout
android:id=&quot;@+id/chatLayout&quot;
android:layout_width=&quot;match_parent&quot;
android:layout_height=&quot;wrap_content&quot;
android:layout_alignParentBottom=&quot;true&quot;
android:gravity=&quot;center&quot;
android:background=&quot;@color/textInputBackground&quot;
android:orientation=&quot;horizontal&quot;&gt;
&lt;!-- ImageButton: to send Image--&gt;
&lt;ImageButton
android:id=&quot;@+id/attachBtn&quot;
android:layout_width=&quot;50dp&quot;
android:layout_height=&quot;50dp&quot;
android:background=&quot;@null&quot;
android:src=&quot;@drawable/ic_attach_black&quot; /&gt;
&lt;!-- EditText: input message--&gt;
&lt;EditText
android:id=&quot;@+id/messageEt&quot;
android:layout_width=&quot;match_parent&quot;
android:layout_height=&quot;wrap_content&quot;
android:layout_weight=&quot;1&quot;
android:background=&quot;@null&quot;
android:inputType=&quot;textCapSentences|textMultiLine&quot;
android:padding=&quot;15dp&quot;
android:hint=&quot;Start typing&quot; /&gt;
&lt;Chronometer
android:id=&quot;@+id/record_timer&quot;
android:layout_width=&quot;wrap_content&quot;
android:layout_height=&quot;wrap_content&quot;
android:visibility=&quot;gone&quot;
android:textSize=&quot;14sp&quot;
android:textColor=&quot;@color/colorPrimary&quot; /&gt;
&lt;!-- Button: voice message--&gt;
&lt;ImageButton
android:id=&quot;@+id/recordBtn&quot;
android:layout_width=&quot;40dp&quot;
android:layout_height=&quot;40dp&quot;
android:background=&quot;@null&quot;
android:src=&quot;@drawable/ic_record_btn_stopped&quot; /&gt;
&lt;!-- Button: send message--&gt;
&lt;ImageButton
android:id=&quot;@+id/sendBtn&quot;
android:layout_width=&quot;40dp&quot;
android:layout_height=&quot;40dp&quot;
android:background=&quot;@null&quot;
android:src=&quot;@drawable/ic_send&quot; /&gt;
&lt;/LinearLayout&gt;

</RelativeLayout>

row_chat_right.xml

&lt;LinearLayout xmlns:android=&quot;http://schemas.android.com/apk/res/android&quot;
android:layout_width=&quot;match_parent&quot;
android:layout_height=&quot;wrap_content&quot;
xmlns:app=&quot;http://schemas.android.com/apk/res-auto&quot;
android:orientation=&quot;vertical&quot;
android:id=&quot;@+id/messageLayout&quot;
android:padding=&quot;10dp&quot;&gt;
&lt;LinearLayout
android:layout_width=&quot;wrap_content&quot;
android:layout_height=&quot;wrap_content&quot;
android:orientation=&quot;horizontal&quot;
android:layout_gravity=&quot;end&quot;&gt;
&lt;de.hdodenhof.circleimageview.CircleImageView
android:layout_width=&quot;50dp&quot;
android:layout_height=&quot;50dp&quot;
android:id=&quot;@+id/profileIv&quot;
app:civ_border_color=&quot;@null&quot;
android:visibility=&quot;gone&quot;
android:src=&quot;@drawable/ic_default_img&quot; /&gt;
&lt;TextView
android:id=&quot;@+id/messageTv&quot;
android:layout_weight=&quot;1&quot;
android:textSize=&quot;16sp&quot;
android:textColor=&quot;@color/textColor&quot;
android:background=&quot;@drawable/bg_sender&quot;
android:padding=&quot;15dp&quot;
android:text=&quot;His Message&quot;
android:visibility=&quot;gone&quot;
android:layout_width=&quot;0dp&quot;
android:layout_height=&quot;wrap_content&quot; /&gt;
&lt;ImageView
android:id=&quot;@+id/messageIV&quot;
android:layout_width=&quot;200dp&quot;
android:layout_height=&quot;200dp&quot;
android:adjustViewBounds=&quot;true&quot;
android:padding=&quot;15dp&quot;
android:src=&quot;@drawable/ic_image_black&quot;
android:scaleType=&quot;fitCenter&quot;
android:background=&quot;@drawable/bg_sender&quot; /&gt;
&lt;RelativeLayout
android:layout_width=&quot;wrap_content&quot;
android:layout_height=&quot;wrap_content&quot;
android:background=&quot;@drawable/bg_sender&quot;
android:orientation=&quot;horizontal&quot; &gt;
&lt;ImageButton
android:id=&quot;@+id/playAudioBtn&quot;
android:visibility=&quot;gone&quot;
android:layout_width=&quot;wrap_content&quot;
android:layout_height=&quot;wrap_content&quot;
android:layout_marginStart=&quot;5dp&quot;
android:layout_marginTop=&quot;20dp&quot;
android:background=&quot;@null&quot;
android:src=&quot;@drawable/ic_play_btn&quot; /&gt;
&lt;SeekBar
android:id=&quot;@+id/messageVoiceSb&quot;
android:visibility=&quot;gone&quot;
android:layout_width=&quot;200dp&quot;
android:layout_height=&quot;wrap_content&quot;
android:layout_toRightOf=&quot;@id/playAudioBtn&quot;
android:padding=&quot;10dp&quot;
android:layout_marginTop=&quot;10dp&quot;
android:max=&quot;100&quot;
android:progress=&quot;0&quot; /&gt;
&lt;TextView
android:id=&quot;@+id/sbCurrentTime&quot;
android:visibility=&quot;gone&quot;
android:text=&quot;0:00&quot;
android:textStyle=&quot;bold&quot;
android:textSize=&quot;12sp&quot;
android:layout_marginStart=&quot;2dp&quot;
android:layout_below=&quot;@id/messageVoiceSb&quot;
android:layout_width=&quot;wrap_content&quot;
android:layout_height=&quot;wrap_content&quot; /&gt;
&lt;TextView
android:id=&quot;@+id/sbTotalDuration&quot;
android:visibility=&quot;gone&quot;
android:textStyle=&quot;bold&quot;
android:text=&quot;0:10&quot;
android:textSize=&quot;12sp&quot;
android:layout_below=&quot;@id/messageVoiceSb&quot;
android:layout_toEndOf=&quot;@id/messageVoiceSb&quot;
android:layout_marginEnd=&quot;12dp&quot;
android:layout_width=&quot;wrap_content&quot;
android:layout_height=&quot;wrap_content&quot; /&gt;
&lt;/RelativeLayout&gt;
&lt;/LinearLayout&gt;
&lt;TextView
android:id=&quot;@+id/timeTv&quot;
android:layout_width=&quot;match_parent&quot;
android:layout_height=&quot;wrap_content&quot;
android:gravity=&quot;end&quot;
android:textAlignment=&quot;textEnd&quot;
android:text=&quot;07/08/2020 23:00PM&quot;
android:textColor=&quot;@color/textColor&quot;
android:textSize=&quot;12sp&quot; /&gt;
&lt;TextView
android:layout_width=&quot;match_parent&quot;
android:layout_height=&quot;wrap_content&quot;
android:id=&quot;@+id/isSeenTv&quot;
android:gravity=&quot;end&quot;
android:textAlignment=&quot;textEnd&quot;
android:text=&quot;delivered&quot; /&gt;

</LinearLayout>

答案1

得分: 0

这里是修正后的内容:

&lt;TextView
android:layout_width="match_parent" &lt;-- 这是我更改的部分
android:layout_height="wrap_content"/&gt;
&lt;SeekBar
android:layout_width="match_parent" &lt;-- 也要检查这个
android:layout_height="wrap_content"/&gt;
英文:

Here is the Fix!!

&lt;TextView
android:layout_width=&quot;match_parent&quot; &lt;-- This is what I changed
android:layout_height=&quot;wrap_content&quot;/&gt;
&lt;SeekBar
android:layout_width=&quot;match_parent&quot; &lt;-- Check this as well
android:layout_height=&quot;wrap_content&quot;/&gt;

huangapple
  • 本文由 发表于 2020年10月13日 02:23:15
  • 转载请务必保留本文链接:https://go.coder-hub.com/64323328.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定