Coder Social home page Coder Social logo

Comments (4)

vikasgoyal09 avatar vikasgoyal09 commented on August 26, 2024

Can you please share your code of header-decor.

from header-decor.

denilsonbarahona avatar denilsonbarahona commented on August 26, 2024

-----------------------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

sin titulo

from header-decor.

ebarrenechea avatar ebarrenechea commented on August 26, 2024

@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.

starkej2 avatar starkej2 commented on August 26, 2024

Duplicate of #7

from header-decor.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.