Search code examples
androidandroid-layoutandroid-activityandroid-cardviewandroid-cards

Cardview wont turn invisible after set visible


I really didn't want to post it here because this problem sounds really stupid and is difficult to describe, but after hiting my head 2 hours for a stupid layout problem i decided to try

I've one activity with several layout components...
During on create all components are set to be invisible just one keeps visible.

When user presses the button, all components turn visible
when presses button again, all components SHOULD turn invisible again

ALL COMPONENTS VISIBILITY IS ADJUST IN ONLY ONE METHOD

so the activity looks like:

 @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.new_giveaway, R.id.mainView);
/*lots of stuff*/
//last thing
   makeVisible(View.INVISIBLE);
}

  private void makeVisible(int visi) {
        findViewById(R.id.cardView).setVisibility(visi);
             ((ViewGroup) findViewById(R.id.influencerLayout)).setVisibility(visi);
        this.recyclerView.setVisibility(visi);
    }

the problem: is on second click all components get invisible but one keeps on screen

the component which stays on is a cardview

Mainlayout:

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
        tools:context="com.tomatedigital.giveawaymaster.activity.NewGiveawayActivity">
//lots of stuff//
      <include layout="@layout/giveaway" />

layout/giveaway is:

  <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/cardView"
        android:layout_width="match_parent"
        android:layout_height="@dimen/giveawayCardHeight"


        card_view:cardCornerRadius="4dp"
        card_view:cardElevation="4dp"
        card_view:cardUseCompatPadding="true">
        //lots of other stuf
</cardview>

It's the first thing i set visible on controller method but the only which doesn't go back invisible

REPEATING: there is no other calls to setVisibility other than these, all visibitilities are controled just under that method

I didn't post the whole activity code here because is way long

==========UPDATE==========

Just to clarify:
1- the cardview is one separated layout file re-used several places
2- there is only one cardview in the mainlayout
3
if i remove makeVisible(View.INVISIBLE)from onCreate(), all stuff stays visible,
if i call makeVisible(View.INVISIBLE) and never call makeVisible(View.VISIBLE) all stuff stays invisible
but if I invisble->visible->invisible everything goes invisible but cardview keeps visible


Solution

  • When you want to set the whole layout to Invisibility state, you need to do it in your include @layout/giveaway.xml. Becouse it is a view too.

    Like we talk in comments...