【发布时间】:2020-05-22 18:05:14
【问题描述】:
您好,很抱歉没有在此页面上添加图片,我还没有足够的声誉
This is how it's supposed to look 和 this 是它在 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);
}
}
}
以及recyclerView代码:
<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