GithubHelp home page GithubHelp logo

Comments (8)

golovin47 avatar golovin47 commented on May 4, 2024 4

Hello, guys. We couldn't reproduce this issue. If there is some custom behavior you want to achieve, you're welcome to fork this lib and apply any customization you need.

from folding-cell-android.

Grohden avatar Grohden commented on May 4, 2024 1

@oleg-vasiliev
I'm facing this issue too after i've updated from 1.0.1 to 1.2.2, i believe that the problem may be:

// make bitmaps from title and content views
Bitmap bitmapFromTitleView = measureViewAndGetBitmap(titleView, this.getMeasuredWidth());
Bitmap bitmapFromContentView = measureViewAndGetBitmap(contentView, this.getMeasuredWidth());
if (skipAnimation) {
contentView.setVisibility(GONE);
titleView.setVisibility(VISIBLE);
FoldingCell.this.mAnimationInProgress = false;
FoldingCell.this.mUnfolded = false;
this.getLayoutParams().height = titleView.getHeight();
} else {
// create empty layout for folding animation
final LinearLayout foldingLayout = createAndPrepareFoldingContainer();
// add that layout to structure
this.addView(foldingLayout);

I'm my case, i'm calling unfold(true) and the measureViewAndGetBitmap calls throw this exception, but they will not be used if i choose to skip animation... so for MY CASE the problem would be solved moving those lines to the else branch that they will be needed (skip animation false)
Also, i've noticed that calling getParent() for the folding cell returns null.. and that may be why the measures return 0 and we get the exception

I'm inflating the view this way :
(FoldingCell) inflater.inflate(R.layout.view_order_list_item, parent, false);
and calling the unfold after, i can't change the attachToView to true because addView(View, LayoutParams) is not supported in AdapterView

Ah, and if its useful, i'm using a ArrayAdapterand not a RecyclerView


My temp solution is

if(cell.getParent() != null){
   cell.unfold(true);
} else {
  //Lay down, try not cry, cry a lot if you need the cell unfolded.
}

from folding-cell-android.

KgotsoK avatar KgotsoK commented on May 4, 2024

I feel your pain. I have been experiencing this since the beginning of time! This is what I'm trying in onBindViewHolder():

switch (itineraryItem.getType()) {
    case ItineraryItem.TYPE_TIME:
            itineraryItemViewHolder.time_foldingcell.setVisibility(View.VISIBLE);
            itineraryItemViewHolder.dist_foldingcell.setVisibility(View.GONE);

            if (unfoldedIndexes.contains(position) && !itineraryItemViewHolder.time_foldingcell.isUnfolded()) {
                        itineraryItemViewHolder.time_foldingcell.unfold(true);
            } else if(!unfoldedIndexes.contains(position) && itineraryItemViewHolder.time_foldingcell.isUnfolded()) {
                itineraryItemViewHolder.time_foldingcell.fold(true);
            }

            break;
        default:
            itineraryItemViewHolder.dist_foldingcell.setVisibility(View.VISIBLE);
            itineraryItemViewHolder.time_foldingcell.setVisibility(View.GONE);

            if (unfoldedIndexes.contains(position) && !itineraryItemViewHolder.dist_foldingcell.isUnfolded()) {
                itineraryItemViewHolder.dist_foldingcell.unfold(true);
            } else if(!unfoldedIndexes.contains(position) && itineraryItemViewHolder.dist_foldingcell.isUnfolded()) {
                itineraryItemViewHolder.dist_foldingcell.fold(true);
            }
            break;
    }

It always gives me the same error when I use the fold() or unfold() method:

java.lang.IllegalArgumentException: width and height must be > 0 at android.graphics.Bitmap.createBitmap(Bitmap.java:969) at android.graphics.Bitmap.createBitmap(Bitmap.java:948) at android.graphics.Bitmap.createBitmap(Bitmap.java:915) at com.ramotion.foldingcell.FoldingCell.measureViewAndGetBitmap(FoldingCell.java:346) at com.ramotion.foldingcell.FoldingCell.unfold(FoldingCell.java:121) at com.ramotion.foldingcell.FoldingCell.toggle(FoldingCell.java:224)

from folding-cell-android.

oleg-vasiliev avatar oleg-vasiliev commented on May 4, 2024

As you can see - it's open source library and you can suggest your own solution for this issue if no one can help. Exception message can give you initial "where to start" information. So all in your hands.

from folding-cell-android.

KgotsoK avatar KgotsoK commented on May 4, 2024

I agree @oleg-vasiliev I like this library, wish I did have the time to debug this and make a pull req.

from folding-cell-android.

miriana-itani avatar miriana-itani commented on May 4, 2024

When I was facing this problem, it was because I was setting the visibility gone on the wrong view.
The visibility gone should be on the cell_content_view. Don't know if anyone have done the same mistake, but maybe it helps someone.

from folding-cell-android.

Grohden avatar Grohden commented on May 4, 2024

I forked this project and made my fixes. They didn't work :/ . So i looked more deep to find out why the measures were all 0, i changed my content_layout visibility from gone to visible and the measures worked (also, the exception was gone too), but in the RecyclerView we need the content to be specifically gone. I've looked at the project code and this:

// hide title and content views
titleView.setVisibility(GONE);
contentView.setVisibility(GONE);
// Measure views and take a bitmaps to replace real views with images
Bitmap bitmapFromTitleView = measureViewAndGetBitmap(titleView, this.getMeasuredWidth());
Bitmap bitmapFromContentView = measureViewAndGetBitmap(contentView, this.getMeasuredWidth());

Was weird, how the view can be measured if it's visibility is GONE?
I did moved the measureViewAndGetBitmap calls to the else branch to get rid of the exception, so this part alone was supposed to work because the of the contentView.setVisibility(VISIBLE);:

if (skipAnimation) {
contentView.setVisibility(VISIBLE);
FoldingCell.this.mUnfolded = true;
FoldingCell.this.mAnimationInProgress = false;
this.getLayoutParams().height = contentView.getHeight();
} else {

But it didn't, contentView.getHeight(); still returns 0.
And that's it, i didn't looked any further into the lib.

But I found a solution for my case, and here it is:

  @Override
  public void onBindViewHolder(@NonNull ViewHolder holder, int position) {
    Model model = items.get(position);
    bindModel(model);

    if (model.shouldBeUnfolded) {
      // Find the content layout
      View content = holder.foldingCell.findViewById(R.id.content_layout);
      // "marks" the content to be visible.
      content.setVisibility(View.VISIBLE);
     
      //"schedule" a fold/unfold AFTER the view HAS measurable height
      holder.foldingCell.post(() -> {
        holder.foldingCell.unfold(true);
      });
    }
  }

from folding-cell-android.

Testator avatar Testator commented on May 4, 2024

this happens when you put include into framelayout

<com.ramotion.foldingcell.FoldingCell
        android:id="@+id/folding_cell"
        folding-cell:backSideColor="#000"
        android:layout_width="match_parent"
        android:layout_height="wrap_content">

        <FrameLayout
            android:id="@+id/cell_content_view"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:visibility="gone">

            <include layout="@layout/cell_content_layout" />

        </FrameLayout>

        <FrameLayout
            android:id="@+id/cell_title_view"
            android:layout_width="match_parent"
            android:layout_height="wrap_content">

            <include layout="@layout/cell_title_layout" />

        </FrameLayout>

    </com.ramotion.foldingcell.FoldingCell>


</LinearLayout>

remove the frame layout and do this if you are using include

<com.ramotion.foldingcell.FoldingCell xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:folding-cell="http://schemas.android.com/apk/res-auto"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    folding-cell:additionalFlipsCount="2"
    folding-cell:animationDuration="1300"
    folding-cell:backSideColor="@color/bgBackSideColor"
    folding-cell:cameraHeight="30">

    <!-- CONTENT (UNFOLDED) LAYOUT (MUST BE AT LEAST 2x times BIGGER than content layout bellow)-->
    <include layout="@layout/cell_content_layout" />

    <!-- TITLE (FOLDED) LAYOUT (MUST BE AT LEAST 2x times SMALLER than content layout above) -->
    <include layout="@layout/cell_title_layout" />

</com.ramotion.foldingcell.FoldingCell>

from folding-cell-android.

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.