当前位置: 首页 > 知识库问答 >
问题:

如何在recyclerview中让横线附加textview?

佘茂才
2023-03-14

现在让我把我到目前为止尝试过的

这是持有回收器视图的布局:

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

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

</RelativeLayout> 

以下是我在活动中使用的recyclerview:

  Recyclerview recyclerView = (RecyclerView) findViewById(R.id.recyclerview);
        recyclerView.setLayoutManager(new LinearLayoutManager(this, LinearLayoutManager.HORIZONTAL, false));
        recyclerView.setHasFixedSize(true);
        TrackingAdapter mAdapter = new TrackingAdapter(this.taskLogModelList,mTaskModel.getTaskID(),fm,String.valueOf(mLastLocation.getLatitude()),String.valueOf(mLastLocation.getLongitude()));
            recyclerView.setAdapter(mAdapter);
            mAdapter.notifyDataSetChanged();

这是使用的适配器:

public class TrackingAdapter extends RecyclerView.Adapter<TrackingAdapter.ViewHolder> {
   private List<TaskLogModel> taskStatusFlowModels;
    private D2DKnocks appclass;
   private String Lat,Long;
    private FragmentManager fragmentManager;
    private String TaskID;
    DateFormat date,msimpleDateformat;
    public TrackingAdapter(List<TaskLogModel> taskStatusFlowModels,String TaskID,FragmentManager context,String Lat,String Long) {
        this.taskStatusFlowModels = taskStatusFlowModels;
        this.fragmentManager=context;
         date=new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        msimpleDateformat = new SimpleDateFormat("hh.mm a");
        this.Lat=Lat;
        this.TaskID=TaskID;
        this.Long=Long;
         appclass=((D2DKnocks)D2DKnocks.getContext());
    }

    public class ViewHolder extends RecyclerView.ViewHolder  implements View.OnClickListener{
        private AvertaTextview txt_time;
        private Rubik txt_delivered;
     //   private AvertaButton btn_start;
        private RelativeLayout layout;
        private View view_right;

        public ViewHolder(View itemView) {
            super(itemView);
            txt_time = itemView.findViewById(R.id.txt_time);
       //     btn_start=itemView.findViewById(R.id.start);
            layout=itemView.findViewById(R.id.layout);
            txt_delivered =  itemView.findViewById(R.id.txt_delivered);
            view_right = (View) itemView.findViewById(R.id.right_view_line);
            layout.setOnClickListener(this);
        }

        @Override
        public void onClick(View view) {
            TaskLogModel taskLogModel=taskStatusFlowModels.get(getAdapterPosition());
            if(taskLogModel.getTaskStatusID()==0){
                TaskStatusDialog taskStatusDialog=new TaskStatusDialog();
                Bundle bundle=new Bundle();
                bundle.putInt("Size",taskStatusFlowModels.size());
                bundle.putString("Lat",Lat);
                bundle.putString("Long",Long);
                bundle.putString("TaskID",TaskID);
                taskStatusDialog.setArguments(bundle);
                taskStatusDialog.show(fragmentManager,"show");
            }

        }
    }

    @Override
    public TrackingAdapter.ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        View itemView = LayoutInflater.from(parent.getContext()).inflate(R.layout.row_view_assignment_status, parent, false);
        return new ViewHolder(itemView);
    }

    @Override
    public void onBindViewHolder(TrackingAdapter.ViewHolder holder, int position) {
             if (taskStatusFlowModels.get(position).getTaskStatusID() > 0) {
                StatusModel statusFlowModel = getStatusName(taskStatusFlowModels.get(position).getTaskStatusID());
                holder.txt_delivered.setText(statusFlowModel.getStatus());
                holder.txt_delivered.setBackgroundResource(R.drawable.btn_arrived_bg);
                 try {
                     Date uppdateDate=date.parse(taskStatusFlowModels.get(position).getUpdateDateTime());
                     String updatedDate=msimpleDateformat.format(uppdateDate);
                     String[] each = updatedDate.split(" ");
                     String str = each[1].replace("AM", "am").replace("PM","pm");

//                     SpannableString ss1=  new SpannableString(each[0]);
//                     SpannableString ss2=new SpannableString(each[1]);
//                     ss1.setSpan(new AbsoluteSizeSpan(20), 0, each[0].length(), SPAN_INCLUSIVE_INCLUSIVE);
//                     ss2.setSpan(new AbsoluteSizeSpan(15), 0, each[1].length(), SPAN_INCLUSIVE_INCLUSIVE);
//                     CharSequence finalText = TextUtils.concat(ss1, " ", ss2);
                    holder.txt_time.setText(each[0]+" "+str);
                 } catch (ParseException e) {
                     e.printStackTrace();
                 }
                 GradientDrawable gradientDrawable = (GradientDrawable) holder.txt_delivered.getBackground();
                gradientDrawable.setColor(Color.parseColor(statusFlowModel.getStatusColor()));
            } else {

                    holder.txt_delivered.setText("Choose");
                    holder.txt_delivered.setBackgroundResource(R.drawable.btn_choose_bg);
                    holder.txt_delivered.setTextColor(Color.parseColor("#b1b1b1"));
            }
            if(taskStatusFlowModels.size()-1==position){
                holder.view_right.setVisibility(View.GONE);
            }
            else {
                holder.view_right.setVisibility(View.VISIBLE);
            }
        }


    public StatusModel getStatusName(Integer statusID){
        for (int i=0;i<appclass.getStatusModelist().size();i++){
            if (appclass.getStatusModelist().get(i).getStatusID().equals(statusID)){
                return appclass.getStatusModelist().get(i);
            }

        }
        return null;
    }
    @Override
    public int getItemCount() {

        return taskStatusFlowModels.size();
    }
}

下面是视图支架布局:

   <?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_marginTop="10dp"
    android:orientation="vertical">


    <RelativeLayout
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:id="@+id/layout">

        <com.trident.Hawkersky.service.CustomFonts.AvertaTextview
            android:id="@+id/txt_time"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_marginLeft="5dp"
            android:drawableLeft="@drawable/ic_checked"
            android:drawablePadding="10dp"
            android:layout_centerHorizontal="true"
            android:gravity="center"
            android:text="10.00 am"
            android:textColor="#444444"
            android:textSize="12sp"
           />

        <View
            android:id="@+id/vertical_line"
            android:layout_width="30dp"
            android:layout_height="20dp"
            android:layout_centerHorizontal="true"
             android:layout_below="@+id/txt_time"
           android:background="@drawable/vertical_dotted_line"
            android:layerType="software"
            android:visibility="visible" />
<RelativeLayout
    android:layout_width="wrap_content"
    android:layout_below="@+id/vertical_line"
    android:layout_height="wrap_content">
        <com.trident.Hawkersky.service.CustomFonts.Rubik
            android:id="@+id/txt_delivered"
            android:layout_centerHorizontal="true"
            android:layout_width="wrap_content"
            android:layout_height="@dimen/thirty"
            android:layout_marginBottom="5dp"
            android:singleLine="true"

            android:padding="@dimen/seven"
            android:background="@drawable/btn_delivered_bg"
            android:gravity="center"
            android:text="Delivered"
            android:textAllCaps="true"
            android:textColor="#FFF"
            android:textSize="13sp"
            android:textStyle="bold" />

        <View
            android:id="@+id/right_view_line" <--- this is the view
            android:layout_width="@dimen/hundred"
            android:layout_height="5dp"
            android:layout_alignBottom="@+id/txt_delivered"
            android:layout_gravity="center_vertical"
            android:layout_marginBottom="12dp"
            android:layout_toEndOf="@+id/txt_delivered"
            android:layout_toRightOf="@+id/txt_delivered"
            android:background="@drawable/dotted"
            android:layerType="software"
            android:visibility="visible" />
</RelativeLayout>
    </RelativeLayout>
</RelativeLayout>

现在我需要的是,我需要这个视图附加到文本视图,但我越来越喜欢上面的图像如何解决它。

共有1个答案

陈志
2023-03-14

请尝试此操作,如果您需要进一步修改,请告知。

<?xml version="1.0" encoding="utf-8"?>
<android.support.constraint.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
                                             xmlns:app="http://schemas.android.com/apk/res-auto"
                                             android:id="@+id/layout"
                                             android:layout_width="wrap_content"
                                             android:layout_height="wrap_content"
                                             android:layout_marginTop="10dp"
                                             android:orientation="vertical">


    <com.trident.Hawkersky.service.CustomFonts.AvertaTextview
        android:id="@+id/txt_time"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_centerHorizontal="true"
        android:layout_marginLeft="5dp"
        android:layout_marginStart="5dp"
        android:drawableLeft="@drawable/ic_checked"
        android:drawablePadding="10dp"
        android:gravity="center"
        android:text="10.00 am"
        app:layout_constraintTop_toTopOf="parent"
        app:layout_constraintLeft_toLeftOf="@+id/txt_delivered"
        app:layout_constraintRight_toRightOf="@+id/txt_delivered"
        android:textColor="#444444"
        android:textSize="12sp"
        />

    <View
        android:id="@+id/vertical_line"
        android:layout_width="30dp"
        android:layout_height="20dp"
        app:layout_constraintLeft_toLeftOf="@+id/txt_delivered"
        app:layout_constraintRight_toRightOf="@+id/txt_delivered"
        android:layout_below="@+id/txt_time"
        android:layout_centerHorizontal="true"
        app:layout_constraintTop_toBottomOf="@+id/txt_time"
        android:background="@color/colorPrimaryDark"
        android:layerType="software"
        android:visibility="visible"/>

    <com.trident.Hawkersky.service.CustomFonts.Rubik
        android:id="@+id/txt_delivered"
        android:layout_width="wrap_content"
        android:layout_height="@dimen/thirty"
        android:layout_marginBottom="5dp"
        android:background="@drawable/btn_delivered_bg"
        android:gravity="center"
        app:layout_constraintTop_toBottomOf="@+id/vertical_line"
        android:padding="@dimen/seven"
        android:singleLine="true"
        android:text="Delivered"
        android:textAllCaps="true"
        android:textColor="#FFF"
        android:textSize="13sp"
        android:textStyle="bold"/>

    <View
        android:id="@+id/right_view_line"
        android:layout_width="100dp"
        android:layout_height="5dp"
        app:layout_constraintTop_toTopOf="@+id/txt_delivered"
        app:layout_constraintBottom_toBottomOf="@+id/txt_delivered"
        app:layout_constraintLeft_toRightOf="@+id/txt_delivered"
        android:background="@drawable/dotted"
        android:layerType="software"
        android:visibility="visible"/>


</android.support.constraint.ConstraintLayout>

对不起,我不得不使用ConstraintLayout。如果您以前没有使用过它,请将此实现'com.android.support.constraint:约束布局:1.0.2'1添加到您的模块级别build.gradle.

 类似资料:
  • 问题内容: 我需要使用childappend或jquery append()将一些标签内容附加到文档中。据我所知,这正在被剥离。有人知道怎么做吗? 问题答案: 尝试这个: 请注意,脚本将加载,并且您可以访问其中的变量,但是您不会在DOM中看到实际的标记。

  • 我需要添加一些空间开始的第一项和结束的最后一项的回收,所以他们可以滚动到屏幕的边缘(因为他们不能与回收器视图的边距或填充) 问题是项目之间的间距应该不同,所以我不能只是将这个“空间”添加到项目布局中。现在,我正试图将ItemEdition添加到我的回收器中,但结果就是这样: 在我触摸它之前,行间距随机出现:随机行间距 然后,当我滚动到最后并返回时,所需的空间出现在屏幕上适合的最后一项之后,而不是在

  • 问题内容: 我打算开发一个可在内显示一些动态数据的应用程序。所以我决定 在main中添加一个 。这是我的应用程序代码: 我的主要活动: 它是布局文件: 在这个rec​​yclerView内部还有另一个: 他们的适配器Main(RAdapter): 和第二个适配器: 我的问题是:正如您在CAdapter中看到的那样,仅显示构造函数的Log消息。 更新:如果有另一种方法可以在另一张动态卡中显示某些动态

  • 但是,如果我尝试将此应用为通过调用访问的可提取资源,则根本不会绘制任何线。 怎么解,这样一条虚线就显示出来了?

  • 一切正常。但Logcat中显示了一些错误。 E/RecyclerView:未附加适配器;跳过布局 E/RecyclerView:未附加适配器;跳过布局 我的activity代码: 我读过与同一问题有关的其他问题,但都没有帮助。请帮帮我