android聊天缩略图位置

玛哈尔·阿列雷扎伊

我有一个带有气泡和缩略图用户图像的对话页面,缩略图位置有问题:当我发送文本缩略图时,必须在右侧显示;当我的朋友发送文本时,其缩略图时必须在左侧显示

我的XML项目是:

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="match_parent"
    android:orientation="horizontal" 
    android:padding="5dp" >

    <LinearLayout
        android:id="@+id/wrapper"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:layout_marginTop="0.5dp" >

        <ImageView
            android:id="@+id/icon"
            android:layout_width="35dp"
            android:layout_height="35dp" 
            android:background="@drawable/user_four"
            android:padding="0dp" />

        <TextView
            android:id="@+id/comment"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_gravity="center"
            android:layout_margin="5dip"
            android:textColor="#2e2e2e"
            android:paddingLeft="10dp" />
    </LinearLayout>

</RelativeLayout>

我的Java代码是:

public class ChatArrayAdapter extends ArrayAdapter<Comment> {

    private TextView countryName;
    private List<Comment> countries = new ArrayList<Comment>();
    private LinearLayout wrapper;


    @Override
    public void add(Comment object) {
        countries.add(object);
        super.add(object);
    }

    public ChatArrayAdapter(Context context, int textViewResourceId) {
        super(context, textViewResourceId);
    }

    public int getCount() {
        return this.countries.size();
    }

    public Comment getItem(int index) {
        return this.countries.get(index);
    }

    public View getView(int position, View convertView, ViewGroup parent) {
        View row = convertView;
        if (row == null) {
            LayoutInflater inflater = (LayoutInflater) this.getContext().getSystemService(Context.LAYOUT_INFLATER_SERVICE);
            row = inflater.inflate(R.layout.listitem_chat, parent, false);
        }

        wrapper = (LinearLayout) row.findViewById(R.id.wrapper);

        Comment coment = getItem(position);

        countryName = (TextView) row.findViewById(R.id.comment);

        countryName.setText(coment.comment);

        countryName.setBackgroundResource(coment.left ? R.drawable.other_bubble : R.drawable.own_bubble);
        wrapper.setGravity(coment.left ? Gravity.LEFT : Gravity.RIGHT);


        return row;
    }

    public Bitmap decodeToBitmap(byte[] decodedByte) {
        return BitmapFactory.decodeByteArray(decodedByte, 0, decodedByte.length);
    }

}
Nanites

如果您在getView()方法中知道文本是您的文本或朋友的文本,则可以根据条件将线性布局的gravity属性更改为left或right。

本文收集自互联网,转载请注明来源。

如有侵权,请联系[email protected] 删除。

编辑于
0

我来说两句

0条评论
登录后参与评论

相关文章

来自分类Dev

android聊天缩略图位置

来自分类Dev

jssor滑块缩略图位置

来自分类Dev

在iOS中设置UISlider的缩略图位置

来自分类Dev

从指定位置获取视频缩略图-Android

来自分类Dev

Android:从Blobstore图片获取缩略图

来自分类Dev

在Android中生成Pdf的缩略图

来自分类Dev

从MediaStore获取全屏缩略图-Android

来自分类Dev

浮动缩略图

来自分类Dev

浮动缩略图

来自分类Dev

PDF缩略图

来自分类Dev

藤蔓缩略图

来自分类Dev

如何更改WooCommerce缩略图的裁剪位置?

来自分类Dev

dropzone.js-如何控制缩略图的显示位置

来自分类Dev

如何获得滚动条缩略图的正确位置?

来自分类Dev

如何在大图中找到缩略图的位置?

来自分类Dev

在Android中为PDF创建缩略图

来自分类Dev

如何在Android中为列表设置缩略图

来自分类Dev

如何在Android中获取视频缩略图?

来自分类Dev

Android:从ContactsProvider检索API级别10的图像或缩略图

来自分类Dev

Android在特定时间创建视频缩略图

来自分类Dev

如何更改Android缩略图以保护敏感数据

来自分类Dev

Android JSON访问缩略图元素

来自分类Dev

无法在Android 10上读取缩略图(loadThumbnail)

来自分类Dev

YouTube缩略图未使用Glide在Android中加载

来自分类Dev

如何删除Android系统图库缩略图

来自分类Dev

Android:从ContactsProvider检索API级别10的图像或缩略图

来自分类Dev

在Android中为PDF创建缩略图

来自分类Dev

android listview视频缩略图滚动问题

来自分类Dev

如何在Android中检索视频缩略图