Comments (4)
Can you please share your code of header-decor.
from 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<PhotoStickyAdapter.ViewHolder> implements
StickyHeaderAdapter<PhotoStickyAdapter.HeaderHolder>{
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
from header-decor.
@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. :)
from header-decor.
Duplicate of #7
from header-decor.
Related Issues (20)
- Is it possible to disable sticking?
- After update adapter and call notifyDataSetChanged it not called headers update.
- using android x but not able to sync "Failed to resolve: com.github.edubarr" HOT 2
- Are you sure you can't release the last update so the library is AndroidX?
- Do not work scroll
- Raymond
- spam
- spam
- Let's get paid
- Is it possible to disable sticking? HOT 3
- Two first headers are not show HOT 1
- Add nullability annotations
- Maintainers wanted! HOT 6
- unable to set headers location properly. HOT 1
- Cannot implement gradle HOT 1
- Failed to resolve: com.github.edubarr HOT 12
- Add continuous integration HOT 4
- Add unit tests HOT 1
- Figure out if header is first in list HOT 2
- Problem with scrolling
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. ๐๐๐
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google โค๏ธ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from header-decor.