在考虑了很多文档之后,我决定分享我的代码和问题。我有一个观点,这是我的下一个观点。 项目网格.xml
<android.support.v7.widget.CardView xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:card_view="http://schemas.android.com/apk/res-auto"
android:id="@+id/card"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="0dp"
android:background="@color/blanco"
card_view:cardCornerRadius="0dp"
card_view:cardElevation="0dp"
card_view:cardUseCompatPadding="true">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<RelativeLayout
android:id="@+id/trlDiaNombre"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1"
android:background="@color/naranjaffb973"
android:minHeight="30dp"
android:visibility="visible">
<TextView
android:id="@+id/txtADPDiaNombre"
android:layout_width="match_parent"
android:layout_height="30dp"
android:gravity="center"
android:singleLine="true"
android:text="DIA"
android:textColor="@color/blanco"
android:textSize="14sp"
android:textStyle="bold" />
</RelativeLayout>
<RelativeLayout
android:id="@+id/rtlDiaNumero"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1"
android:gravity="center"
android:minHeight="40dp">
<TextView
android:id="@+id/txtADPDiaNumero"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center"
android:text="6"
android:textColor="@color/morao_moraito_8C008C"
android:textSize="18sp" />
</RelativeLayout>
</LinearLayout>
</android.support.v7.widget.CardView> 就是简单的两个Textview。
它是适配器这是膨胀视图适配器的适配器 。java
public class CustomAdapterListadoFechasRCV
extends
RecyclerView.Adapter<CustomAdapterListadoFechasRCV.ElementosLinea> {
private ArrayList<Cdia> mDataset;
private AfrmProgramaControl afrmGes;
// Provide a reference to the views for each data item
// Complex data items may need more than one view per item, and
// you provide access to all the views for a data item in a view holder
public class ElementosLinea extends RecyclerView.ViewHolder {
// each data item is just a string in this case
TextView txtNombre;
TextView txtNumero;
RelativeLayout rtlNombre;
RelativeLayout rtlNumero;
// CardView card;
public ElementosLinea(View v) {
super(v);
ArrayList<CUtilsTipografia.CtipoGraf> lstTipograf = new ArrayList<CUtilsTipografia.CtipoGraf>();
// card = (CardView) v.findViewById(R.id.card);
txtNombre = (TextView) v.findViewById(R.id.txtADPDiaNombre);
txtNumero = (TextView) v.findViewById(R.id.txtADPDiaNumero);
rtlNombre = (RelativeLayout) v.findViewById(R.id.trlDiaNombre);
rtlNumero = (RelativeLayout) v.findViewById(R.id.rtlDiaNumero);
lstTipograf.add(new CUtilsTipografia.CtipoGraf(txtNombre, 0, 1));
lstTipograf.add(new CUtilsTipografia.CtipoGraf(txtNumero, 0, 0));
CUtilsTipografia.setTypefaces(afrmGes.getActivity(), lstTipograf);
}
}
public void add(int position, Cdia item) {
mDataset.add(position, item);
notifyItemInserted(position);
}
public void remove(Cdia item) {
int position = mDataset.indexOf(item);
mDataset.remove(position);
notifyItemRemoved(position);
}
// Provide a suitable constructor (depends on the kind of dataset)
public CustomAdapterListadoFechasRCV(
ArrayList<Cdia> myDataset, AfrmProgramaControl afrm) {
mDataset = myDataset;
afrmGes = afrm;
}
// Create new views (invoked by the layout manager)
@Override
public ElementosLinea onCreateViewHolder(
ViewGroup parent, int viewType) {
// create a new view
View v = LayoutInflater.from(parent.getContext()).inflate(
R.layout.ll_adapter_listado_fechas, parent, false);
// set the view's size, margins, paddings and layout parameters
ElementosLinea vh = new ElementosLinea(v);
return vh;
}
// Replace the contents of a view (invoked by the layout manager)
@Override
public void onBindViewHolder(ElementosLinea holder, final int position) {
// - get element from your dataset at this position
// - replace the contents of the view with that element
final Cdia datossss = mDataset.get(position);
if (datossss != null) {
if (datossss.getDia() == -1) {//s
holder.rtlNombre.setVisibility(View.VISIBLE);
holder.rtlNumero.setVisibility(View.GONE);
holder.txtNombre.setText(datossss.getNombreDia());
} else {
holder.rtlNombre.setVisibility(View.GONE);
holder.rtlNumero.setVisibility(View.VISIBLE);
if (datossss.getDia() != 0) {
if (datossss.getMarcado() == 1) {
holder.txtNumero.setTextColor(afrmGes.getResources().getColor(R.color.marcacalendarioff4000));
} else {
holder.txtNumero.setTextColor(afrmGes.getResources().getColor(R.color.grisclarod8d8d8));
}
holder.txtNumero.setText(String.valueOf(datossss.getDia()));
} else {
holder.txtNumero.setText("");
}
}
//
}
holder.rtlNumero.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Cdia dia = mDataset.get(position);
afrmGes.cargarProgramaDia(dia);
}
});
}
// Return the size of your dataset (invoked by the layout manager)
@Override
public int getItemCount() {
return mDataset.size();
}
}
如您所见,我的适配器只需要天数列表 Cdia.java
public class Cdia {
private int _iDia;
private String _sNombreDia;
private int _iMarcado;
private int _iMes;
public Cdia() {
_iDia = 0;
_sNombreDia = "";
_iMarcado = 0;
_iMes =0;
}
public int getDia() {
return _iDia;
}
public void setDia(int _iDia) {
this._iDia = _iDia;
}
public String getNombreDia() {
return _sNombreDia;
}
public void setNombreDia(String _sNombreDia) {
this._sNombreDia = _sNombreDia;
}
public int getMarcado() {
return _iMarcado;
}
public void setMarcado(int _iMarcado) {
this._iMarcado = _iMarcado;
}
public int getMes() {
return _iMes;
}
public void setMes(int _iMes) {
this._iMes = _iMes;
}
一切准备就绪后,我将解释我的问题,这个 gridLayoutManages 的 dispodicion 分为七列,这样我生成了两个月,每列对应的日历日如下所示。
自从成为数据列表的适配器,直到它在裤装中经过太长时间,超过 4 秒。这就是我的适配器有多满。
我没有找到解决我的加载速度问题的方法,有人可以在我的黑暗之路上给我光明吗?谢谢。
更新 coment :
public class GridViewReciclerObservable extends ObservableRecyclerView {
//para ponerle el tipo linear
private GridLayoutManagerCustom mLayoutManager;
private int _iColumnas = 7;
public GridViewReciclerObservable(Context context, AttributeSet attrs, int defStyle) {
super(context, attrs, defStyle);
mLayoutManager = new GridLayoutManagerCustom(getContext(), _iColumnas);
setLayoutManager(mLayoutManager);
LayoutParams par = new LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT);
setLayoutParams(par);
}
public GridViewReciclerObservable(Context context, AttributeSet attrs) {
super(context, attrs);
mLayoutManager = new GridLayoutManagerCustom(getContext(), _iColumnas);
setLayoutManager(mLayoutManager);
LayoutParams par = new LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT);
setLayoutParams(par);
// TODO Auto-generated constructor stub
}
public GridViewReciclerObservable(Context context) {
super(context);
mLayoutManager = new GridLayoutManagerCustom(getContext(), _iColumnas);
setLayoutManager(mLayoutManager);
LayoutParams par = new LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT);
setLayoutParams(par);
// TODO Auto-generated constructor stub
}
}
VIEWPARENT
<?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="match_parent"
android:background="@color/blanco">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<TextView
android:id="@+id/txtMesEnCurso"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center"
android:text="New Text"
android:layout_margin="5dp"
android:textSize="25sp"
android:textColor="@color/gris444444">
</TextView>
<com.jesusdelarosainfante.herramientas.view.GridViewReciclerObservable
android:id="@+id/rcvGCalen"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_margin="5dp"
android:scrollbars="vertical" />
</LinearLayout>
</RelativeLayout>