Android:RecyclerView中的TextView对齐

时间:2019-05-13 02:02:51

标签: android xml android-recyclerview

我的RecyclerView有问题。问题是,单词“ Pending”未位于RecyclerView的右侧。由于我的声誉,我无法发布图片。在下面,我给出了当前RecyclerView的链接。

https://scontent.fkul14-1.fna.fbcdn.net/v/t1.0-9/60160733_10216106491068205_5066642184581677056_n.jpg?_nc_cat=107&_nc_ht=scontent.fkul14-1.fna&oh=0a839d9c678868a4fd5bd814754e4f66&oe=5D598369

然后,下面是我当前的XML代码。

suggestion_list.xml

<FrameLayout 
      xmlns:android="http://schemas.android.com/apk/res/android"
      android:layout_width="match_parent"
      android:layout_height="wrap_content">

        <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:orientation="vertical">

        <TableRow
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_marginLeft="20dp"
            android:layout_marginTop="05dp"
            android:layout_marginRight="20dp">

            <TextView
                android:id="@+id/tvTitle"
                android:layout_width="fill_parent"
                android:layout_height="wrap_content"
                android:layout_weight="1"
                android:gravity="left"
                android:text="Name"
                android:textColor="@color/colorAccent"
                android:textAppearance="@style/Base.TextAppearance.AppCompat.Large"
                android:textStyle="bold"/>

            <TextView
                android:id="@+id/tvStatus"
                android:layout_width="fill_parent"
                android:layout_height="wrap_content"
                android:layout_weight="2"
                android:gravity="right"
                android:text="Pending"
                android:textColor="#F50808" />
        </TableRow>

        <TableRow
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:layout_marginLeft="20dp"
            android:layout_marginTop="05dp"
            android:layout_marginRight="20dp">

            <TextView
                android:id="@+id/tvName"
                android:layout_width="fill_parent"
                android:layout_height="wrap_content"
                android:layout_weight="1"
                android:text="Name"
                android:textColor="@color/colorAccent" />
        </TableRow>

        <TableRow
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:layout_marginLeft="20dp"
            android:layout_marginTop="05dp"
            android:layout_marginRight="20dp">

            <TextView
                android:id="@+id/tvMonth"
                android:layout_width="fill_parent"
                android:layout_height="wrap_content"
                android:layout_weight="1"
                android:text="Month"
                android:textColor="@color/colorAccent" />
            </TableRow>
    </LinearLayout>
</FrameLayout>

activity_my_history_list.xml

<LinearLayout 
     xmlns:android="http://schemas.android.com/apk/res/android"
     xmlns:tools="http://schemas.android.com/tools"
     android:layout_width="match_parent"
     android:id="@+id/haha"
     android:layout_height="match_parent"
     android:orientation="vertical"
     tools:context=".MyHistoryList">

<TextView
    android:id="@+id/title"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:gravity="center"
    android:maxLines="1"
    android:clickable="false"
    android:focusable="false"
    android:longClickable="false"
    android:textStyle="bold"
    android:textSize="18sp"
    android:textColor="#FFFFFF" />

<LinearLayout
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:orientation="vertical">

    <android.support.v7.widget.RecyclerView
        android:id="@+id/recylcerView"
        android:layout_width="match_parent"
        android:layout_height="match_parent"/>

</LinearLayout>

UserAdapter.java

public class UserAdapter extends RecyclerView.Adapter<UserAdapter.ProductViewHolder> {

private Context mCtx;
private List<User> userList;
private View.OnClickListener mClickListener;

public UserAdapter(Context mCtx, List<User> userList) {
    this.mCtx = mCtx;
    this.userList = userList;
}

public void setClickListener(View.OnClickListener callback) {
    mClickListener = callback;
}

@Override
public ProductViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
    LayoutInflater inflater = LayoutInflater.from(mCtx);
    View view = inflater.inflate(R.layout.suggestion_list, null);

    RecyclerView.ViewHolder holder = new ProductViewHolder(view);
    holder.itemView.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View view) {
            mClickListener.onClick(view);
        }
    });

    return new ProductViewHolder(view);
}

@Override
public void onBindViewHolder(ProductViewHolder holder, int position) {
    User user = userList.get(position);

        holder.tvTitle.setText(user.getTitle());
        holder.tvStatus.setText(user.getStatus());
        holder.tvName.setText(user.getName());
        holder.tvMonth.setText(user.getMonth());
        holder.id = user.getId();
}

@Override
public int getItemCount() {
    return userList.size();
}

class ProductViewHolder extends RecyclerView.ViewHolder {

    TextView tvTitle, tvName, tvMonth, tvStatus;
    int id;

    public ProductViewHolder(View itemView) {
        super(itemView);
        tvTitle = itemView.findViewById(R.id.tvTitle);
        tvName = itemView.findViewById(R.id.tvName);
        tvMonth = itemView.findViewById(R.id.tvMonth);
        tvStatus = itemView.findViewById(R.id.tvStatus);
    }
}

}

因此,我希望“待定”一词始终正确。到底是什么问题?有什么建议吗?

0 个答案:

没有答案