Android 回收视图项组件重叠
在第二项中,它似乎是重叠的元素。这可能是由于较长的文本长度,但我无法修复它。 fragment_meds.xmlAndroid 回收视图项组件重叠,android,android-layout,android-recyclerview,Android,Android Layout,Android Recyclerview,在第二项中,它似乎是重叠的元素。这可能是由于较长的文本长度,但我无法修复它。 fragment_meds.xml AllMedicineRecycleServiceAdapter.java public类AllMedicineRecycleServiceAdapter扩展了RecycleView.Adapter{ 私人最终清单价值; 私有最终AllMedicineFragment.OnListFragmentInteractionListener MLListener; 语境; dbdb;
AllMedicineRecycleServiceAdapter.java
public类AllMedicineRecycleServiceAdapter扩展了RecycleView.Adapter{
私人最终清单价值;
私有最终AllMedicineFragment.OnListFragmentInteractionListener MLListener;
语境;
dbdb;
私有列表mMedicineData=newarraylist();
public AllMedicineRecycleServiceAdapter(列表项,AllMedicineFragment.OnListFragmentInteractionListener,上下文上下文){
M值=项目;
mListener=监听器;
this.context=上下文;
}
@凌驾
public ViewHolder onCreateViewHolder(视图组父级,int-viewType){
View=LayoutInflater.from(parent.getContext())
.充气(R.layout.fragment_meds,母体,假);
db=新的DbHelper(上下文);
返回新的ViewHolder(视图);
}
@凌驾
公共无效onBindViewHolder(最终视图持有人,最终整型位置){
holder.mItem=mValues.get(位置);
holder.mIdView.setText(mValues.get(position.getMedicine().getName());
holder.resupply_按钮.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(“测试添加包”、“添加”);
holder.resupply_按钮.setText(R.string.added_to_resupply);
固定器。再补给按钮。设置复合可拉伸开关(R.drawable.check,0,0,0);
}否则{
Log.e(“测试添加包”,“添加”);
holder.resupply_按钮.setText(R.string.add_to_resupply);
固定器。再补给按钮。设置复合可抽取开关(R.可抽取。再补给,0,0,0);
}
}否则{
对于(int i=0;i<?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>
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() + "'";
}
}
}
<?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>
<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" />