Domanda

I'm looking for a way to display a "stand-by screen" for within my app.

I have a main activity with a fragment and I've added a button to the side of the main activity to trigger when this "Stand-by" screen should show, which will be nothing more than displaying a picture.

I have already tried changing the content view, it works for setting the screen but when I try set it back to activity_main it throws an error about being unable to inflate the fragment.

Which lead me to try creating a linearlayout view programmatically (spelling?) and setting this view visible with setvisibility but this doesn't work either.

I have also looked at AlertDialog but I don't think this is the best way to do this.

Thank you for reading

È stato utile?

Soluzione

The easiest? add an ImageView or any View with opaque background as the last element of your layout, with dimensions MATCH_PARENT / MATCH_PARENT and Visibility GONE.

When you want to show it, just call view.setVisibility(View.VISIBLE) , or view.setVisiblity(View.GONE) to hide it. It will come up above the rest of elements, which will be hidden under its opaque background.

View view=findViewById(R.id.yourSplashId);

show

view.setVisibility(View.VISIBLE);

hide

view.setVisibility(View.GONE);

I see in your question that you tried this approach and it didn't work. Maybe that View you generated was behind the fragment?

You can also put your Fragment + splash inside a ViewFlipper

<ViewFlipper>
     <fragment>...</fragment>
     <FrameLayout>
         <imageView>
         <progressbar> .. etc
     </FrameLayout>
</ViewFlipper>

this has the added benefit that you can setup animations for transitions etc.. In this case:

ViewFlipper myFlipper=findViewById(R.id.myFlipper);
myFlipper.setDisplayedChild(0); // fragment
myFlipper.setDisplayedChild(1);  // splash

and

myFlipper.setInAnimation(AnimationUtils.loadAnimation(v.getContext(), R.anim.left_in));
myFlipper.setOutAnimation(AnimationUtils.loadAnimation(v.getContext(), R.anim.right_out));
Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top