2017-07-28 74 views
0

在第二個項目中它似乎是重疊元素。它可能是由於較長的文本,但我無法修復它。 fragment_meds.xmlRecycle-view項目組件重疊

<?xml version="1.0" encoding="utf-8"?> 

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:layout_width="match_parent" 
    android:layout_height="175dp" 
    android:orientation="horizontal"> 
    <LinearLayout 
     android:layout_width="0dp" 
     android:layout_weight="0.35" 
     android:layout_height="match_parent" 
     android:padding="10dp" 
     android:orientation="vertical"> 
     <ImageView 

      android:background="@drawable/default_meds_small" 
      android:layout_width="100dp" 
      android:layout_height="100dp" /> 
    </LinearLayout> 

    <LinearLayout 
     android:layout_width="0dp" 
     android:layout_height="match_parent" 
     android:layout_weight="0.65" 
     android:paddingTop="10dp" 
     android:orientation="vertical"> 

     <TextView 
      android:id="@+id/id" 
      android:layout_gravity="left" 
      android:textStyle="bold" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:textColor="@color/black" 
      /> 

     <TextView 

      android:id="@+id/content" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:textColor="@color/black" 
      /> 
     <TextView 
      android:drawableLeft="@drawable/resupply" 
      android:id="@+id/resupply_button" 
      android:drawablePadding="5dp" 
      android:textColor="@color/black" 
      android:text="@string/add_to_resupply" 
      android:layout_width="wrap_content" 
      android:layout_gravity="right" 
      android:layout_marginTop="40dp" 
      android:layout_height="20dp" /> 
    </LinearLayout> 
</LinearLayout> 

AllMedicineRecyclerViewAdapter.java

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

    private final List<MedicineList> mValues; 
    private final AllMedicineFragment.OnListFragmentInteractionListener mListener; 
    Context context; 
    DbHelper db; 
    private List<com.allion.medimap.dto.Medicine> mMedicineData = new ArrayList<com.allion.medimap.dto.Medicine>(); 

    public AllMedicineRecyclerViewAdapter(List<MedicineList> items, AllMedicineFragment.OnListFragmentInteractionListener listener, Context context) { 
     mValues = items; 
     mListener = listener; 
     this.context = context; 

    } 

    @Override 
    public ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) { 
     View view = LayoutInflater.from(parent.getContext()) 
       .inflate(R.layout.fragment_meds, parent, false); 
     db = new DbHelper(context); 
     return new ViewHolder(view); 
    } 

    @Override 
    public void onBindViewHolder(final ViewHolder holder, final int position) { 
     holder.mItem = mValues.get(position); 
     holder.mIdView.setText(mValues.get(position).getMedicine().getName()); 

     holder.resupply_button.setText(R.string.add_to_resupply); 
     mMedicineData = db.getAllMedicine(); 
     Log.e("adpater", "start"); 
     Log.e("size", String.valueOf(mMedicineData.size())); 


     if (mValues.get(position).getMedicine().getMed_id().equals("pack_med")) { 
      if (SessionManager.getInstance(context).getPack()) { 
       Log.e("test_add_pack", "add"); 

       holder.resupply_button.setText(R.string.added_to_resupply); 
       holder.resupply_button.setCompoundDrawablesWithIntrinsicBounds(R.drawable.check, 0, 0, 0); 

      } else { 
       Log.e("test_add_pack", "added"); 

       holder.resupply_button.setText(R.string.add_to_resupply); 
       holder.resupply_button.setCompoundDrawablesWithIntrinsicBounds(R.drawable.resupply, 0, 0, 0); 
      } 
     } else { 
      for (int i = 0; i < mMedicineData.size(); i++) { 
       if(mValues.get(position).getMedicine().getCategory().equals("prn")) 
       { 
        holder.resupply_button.setVisibility(View.GONE); 
       } 
       else { 

        if (mValues.get(position).getMedicine().getName().equals(mMedicineData.get(i).getName())) { 
         Log.e("true_name1", mMedicineData.get(i).getId()); 
         Log.e("true_name2", mValues.get(position).getMedicine().getMed_id()); 

         holder.resupply_button.setText(R.string.added_to_resupply); 
         holder.resupply_button.setCompoundDrawablesWithIntrinsicBounds(R.drawable.check, 0, 0, 0); 

        } 
       } 
      } 
     } 


     holder.mView.setOnClickListener(new View.OnClickListener() { 
      @Override 
      public void onClick(View v) { 
       if (null != mListener) { 

        if (!mValues.get(position).getMedicine().getMed_id().equals("pack_med")) { 
         startMedicineDetailFromTimelineActivity(context, mValues.get(position).getMedicine()); 
         mListener.onListFragmentInteraction(holder.mItem); 
        } 
       } 
      } 
     }); 
     holder.resupply_button.setOnClickListener(new View.OnClickListener() { 
      @Override 
      public void onClick(View v) { 

       if (mValues.get(position).getMedicine().getMed_id().equals("pack_med")) { 
        if (SessionManager.getInstance(context).getPack()) { 
         Log.e("test_add_pack", "add"); 
         SessionManager.getInstance(context) 
           .setPack(context, false); 
         holder.resupply_button.setText(R.string.add_to_resupply); 
         holder.resupply_button.setCompoundDrawablesWithIntrinsicBounds(R.drawable.resupply, 0, 0, 0); 

        } else { 
         Log.e("test_added_pack", "added"); 
         SessionManager.getInstance(context) 
           .setPack(context, true); 
         holder.resupply_button.setText(R.string.added_to_resupply); 
         holder.resupply_button.setCompoundDrawablesWithIntrinsicBounds(R.drawable.check, 0, 0, 0); 
        } 

       } else { 
        if (holder.resupply_button.getText().toString().equals("Add To Resupply")) { 

         Log.e("test_added", "added"); 
         com.allion.medimap.dto.Medicine medicine = new com.allion.medimap.dto.Medicine(mValues.get(position).getMedicine().getMed_id(), mValues.get(position).getMedicine().getName(), mValues.get(position).getMedicine().getCategory()); 
         db.insertMedicineDetail(medicine); 
         holder.resupply_button.setText(R.string.added_to_resupply); 
         holder.resupply_button.setCompoundDrawablesWithIntrinsicBounds(R.drawable.check, 0, 0, 0); 
        } else { 
// 
         db.deleteRow(mValues.get(position).getMedicine().getMed_id()); 
         holder.resupply_button.setText(R.string.add_to_resupply); 
         holder.resupply_button.setCompoundDrawablesWithIntrinsicBounds(R.drawable.resupply, 0, 0, 0); 
         Log.e("test_add", "added"); 

// 
        } 
       } 

      } 
     }); 
    } 

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

    @Override 
    public int getItemViewType(int position) { 

     return position; 
    } 

    public class ViewHolder extends RecyclerView.ViewHolder { 
     public final View mView; 
     public final TextView mIdView; 
     public final TextView mContentView; 
     public final TextView resupply_button; 
     public MedicineList mItem; 

     public ViewHolder(View view) { 
      super(view); 
      mView = view; 
      mIdView = (TextView) view.findViewById(R.id.id); 
      mContentView = (TextView) view.findViewById(R.id.content); 
      resupply_button = (TextView) view.findViewById(R.id.resupply_button); 

     } 

     @Override 
     public String toString() { 
      return super.toString() + " '" + mContentView.getText() + "'"; 
     } 


    } 


} 

上面我增加了相關法規與我在這裏需要提及我禁用回收項目的可重用性功能 - 查看。如果有人能幫我解決這個問題,我將不勝感激。

回答

2

嘗試像這樣

<?xml version="1.0" encoding="utf-8"?> 
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" 
android:layout_width="match_parent" 
android:layout_height="175dp" 
android:orientation="horizontal"> 
<ImageView 
    android:id="@+id/iv" 
    android:layout_width="100dp" 
    android:layout_height="100dp" 
    android:padding="10dp" 
    android:src="@drawable/default_meds_small"/> 


<LinearLayout 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    android:layout_toRightOf="@+id/iv" 
    android:paddingTop="10dp" 
    android:orientation="vertical"> 

    <TextView 
     android:id="@+id/id" 
     android:layout_gravity="left" 
     android:textStyle="bold" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:textColor="@color/black" 
     /> 

    <TextView 

     android:id="@+id/content" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:textColor="@color/black" 
     /> 
    <TextView 
     android:drawableLeft="@drawable/resupply" 
     android:id="@+id/resupply_button" 
     android:drawablePadding="5dp" 
     android:textColor="@color/black" 
     android:text="@string/add_to_resupply" 
     android:layout_width="wrap_content" 
     android:layout_gravity="right" 
     android:layout_marginTop="40dp" 
     android:layout_height="20dp" /> 
</LinearLayout> 
</RelativeLayout> 
+0

精彩answer.I的固定的問題。 – HRCJ

+0

很高興它幫助你。您可以將其標記爲答案,以便可以關閉問題。 – Anmol

2

而是採用的LinearLayout只有一個小部件,你可以使用ImageView的直接像

<ImageView 
    android:background="@drawable/default_meds_small" 
    android:layout_width="100dp" 
    android:layout_height="100dp" 
    android:adjustViewBound="true" 
    android:padding="10dp" 
    android:layout_weight="0.35" />