如何在recyclerview中制作水平线附加textview?

时间:2018-01-22 06:52:21

标签: android android-recyclerview

我怀疑如何在循环播放器视图中填充时如何使水平视图触摸textview,现在让我简单解释一下我在该适配器视图持有者中有一个水平回收视图我在textview末尾有水平视图,这是中心垂直于该文本视图,因此在添加项目时,每个视图必须触摸文本视图,如垂直虚线时间轴,但视图未触及textview,如下图所示。enter image description here

现在让我发布我到目前为止所尝试的内容

这是持有recyclerview的布局:

<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>

现在我需要的是我需要将该视图附加到textview上,但我得到的图像如何解决它。

1 个答案:

答案 0 :(得分:1)

请尝试这一点,并告知您是否需要进一步修改。

<?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。如果您以前没有使用过它,请将此implementation 'com.android.support.constraint:constraint-layout:1.0.2'1添加到您的模块级build.gradle。