Closed denilsonbarahona closed 8 years ago
Can you please share your code of header-decor.
-----------------------this is the code of the activity -------------------------------
public class PhotoContent extends Fragment {
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
}
@Nullable
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
RecyclerView photoList = (RecyclerView)inflater.inflate(
R.layout.content_images, container, false).findViewById(R.id.photo_list);
final PhotoStickyAdapter photoAdapter = new PhotoStickyAdapter(getContext());
StickyHeaderDecoration PhotoDecorationHeader = new StickyHeaderDecoration(photoAdapter);
GridLayoutManager Photomanager = new GridLayoutManager(getActivity(),3);
photoList.setAdapter(photoAdapter);
photoList.setHasFixedSize(true);
photoList.setLayoutManager(Photomanager);
photoList.addItemDecoration(PhotoDecorationHeader);
return photoList;
}
}
------- this is the code of the adapter ------------------------------
public class PhotoStickyAdapter extends RecyclerView.Adapter
private LayoutInflater photoInflater;
private TypedValue PhotoRipleTypeValue = new TypedValue();
private int photoRipleValue;
private Context contextInt;
public PhotoStickyAdapter(Context context) {
contextInt = context;
photoInflater = LayoutInflater.from(context);
}
public static Bitmap decodeBitmapPhoto(Resources res , int resId , int reqWidth , int reqHeight){
final BitmapFactory.Options options = new BitmapFactory.Options();
options.inJustDecodeBounds=true;
BitmapFactory.decodeResource(res,resId,options);
options.inSampleSize = PhotoCalculateSize(options,reqWidth,reqHeight);
options.inJustDecodeBounds = false;
return BitmapFactory.decodeResource(res,resId,options);
}
public static int PhotoCalculateSize(BitmapFactory.Options option,int reqWidth , int reqHeight) {
final int height = option.outHeight;
final int width = option.outWidth;
int insampleSize = 1;
if (height > reqHeight || width > reqWidth){
final int halfHeigth = height/2;
final int halfWidth = width/2;
while((halfHeigth/insampleSize)>reqHeight && (halfWidth/insampleSize)>reqWidth )
{
insampleSize*=2;
}
}
return insampleSize;
}
@Override
public ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
View view = LayoutInflater.from(parent.getContext()).inflate(R.layout.photo_content,parent,false);
return new ViewHolder( view );
}
@Override
public void onBindViewHolder(final ViewHolder holder, int position) {
// holder.Photo.setImageResource( R.drawable.photo );
holder.Photo.setImageBitmap(decodeBitmapPhoto(contextInt.getResources(),R.drawable.photo,100,100));
}
@Override
public int getItemCount() {
return 20;
}
@Override
public long getHeaderId(int position) {
return (long) position/2;
}
@Override
public HeaderHolder onCreateHeaderViewHolder(ViewGroup parent) {
View view = photoInflater.inflate(R.layout.photo_header,parent,false);
return new HeaderHolder(view);
}
@Override
public void onBindHeaderViewHolder(HeaderHolder viewholder, int position) {
viewholder.header.setText("0"+(getHeaderId(position)+1)+" Diciembre");
}
public class ViewHolder extends RecyclerView.ViewHolder {
public ImageView Photo;
public ViewHolder(View itemView) {
super(itemView);
Photo = (ImageView) itemView.findViewById(R.id.photo_show);
}
}
public class HeaderHolder extends RecyclerView.ViewHolder {
public TextView header;
public HeaderHolder(View itemView) {
super(itemView);
header = (TextView) itemView.findViewById(R.id.header_photo);
}
} }
------------------ this is the result
@denilsonbarahona using a GridLayoutManager
isn't really supported at the moment, as mentioned in #7. You are welcome to make changes to the library and make it work. :)
Duplicate of #7
hi i´m trying to use the header -Decor with the gridLayoutmanager but when i uses it all the information in the recycleview is in disorder