RecyclerView项目不按预期显示

问题描述 投票:1回答:1

你好,很抱歉没有在这个页面上添加图片,我还没有足够的信誉。

这就是它应该有的样子这个 是在recyclerView中的显示方式,如你所见,我希望图片在左边,文字在右边居中,如何实现呢?

下面是项目布局的代码

    xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:padding="10dip"
    >

    <de.hdodenhof.circleimageview.CircleImageView
        android:id="@+id/imgRowCompany"
        android:layout_width="115dp"
        android:layout_height="80dp"
        android:layout_centerVertical="true"
        android:layout_marginStart="16dp"
        android:layout_marginTop="16dp"
        android:layout_marginBottom="16dp"
        android:clickable="false"
        android:src="@drawable/library_icon"

        android:visibility="visible"
        app:civ_border_color="@color/Blue"
        app:civ_border_width="2.5dp"
        app:layout_constraintBottom_toBottomOf="parent"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toTopOf="parent" />

    <TextView
        android:id="@+id/txtRowCompanyName"
        android:layout_width="0dp"
        android:layout_height="46dp"
        android:layout_centerVertical="true"
        android:layout_marginStart="20dp"
        android:layout_marginTop="30dp"
        android:layout_marginBottom="30dp"
        android:text="CompanyName"
        android:textColor="#000000"
        android:textSize="25sp"
        app:layout_constraintBottom_toBottomOf="parent"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintStart_toEndOf="@+id/imgRowCompany"
        app:layout_constraintTop_toTopOf="parent" />

</androidx.constraintlayout.widget.ConstraintLayout>

recyclerAdapter代码。

public class RecyclerAdapter extends RecyclerView.Adapter<RecyclerAdapter.ViewHolder> {

    @NonNull
    @Override
    public ViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {

        LayoutInflater layoutInflater = LayoutInflater.from(parent.getContext());
        View view = layoutInflater.inflate(R.layout.recycler_item,parent,false);
        ViewHolder viewHolder = new ViewHolder(view);

        return viewHolder;
    }

    @Override
    public void onBindViewHolder(@NonNull ViewHolder holder, int position) {

    }

    @Override//Number od items to be returned
    public int getItemCount() {
        return 10;
    }

    static class ViewHolder extends RecyclerView.ViewHolder {
       CircleImageView imageRowCompany;
       TextView companyName;

        public ViewHolder(@NonNull View itemView) {
            super(itemView);

            imageRowCompany=itemView.findViewById(R.id.imgRowCompany);
            companyName=itemView.findViewById(R.id.txtRowCompanyName);
        }
    }
}

还有回收器视图的代码:

<androidx.constraintlayout.widget.ConstraintLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    tools:context=".CompanyLibrary"
    >

    <androidx.recyclerview.widget.RecyclerView
        android:id="@+id/recyclerView"
        android:layout_width="0dp"
        android:layout_height="0dp"
        app:layout_constraintBottom_toBottomOf="parent"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toTopOf="parent"
        app:layoutManager="androidx.recyclerview.widget.LinearLayoutManager"
        />
</androidx.constraintlayout.widget.ConstraintLayout>

任何帮助将被感激,谢谢

android android-layout android-recyclerview recycler-adapter
1个回答
2
投票

你发的图片是在RTL设备上。从头到尾和从头到尾是预期的工作方式,如果你想以你的方式显示,那么使用

app:layout_constraintRight_toRightOf="parent" instead of 
app:layout_constraintEnd_toEndOf="parent"

app:layout_constraintLeft_toLeftOf="parent" instead of 
app:layout_constraintStart_toStartOf="parent"
© www.soinside.com 2019 - 2024. All rights reserved.