0

I have a strange error when exiting the app and reentering it ,the ShowcaseView is not centered,I use this code in a Fragment. This my code for :

target = new ViewTarget(iv_QR);
            if (showcase == null) {
                Button button = new Button(getContext());
                button.setText("Got it !");
                button.setEnabled(false);
                button.setVisibility(View.INVISIBLE);
                showcase = new ShowcaseView.Builder(getActivity())
                        .setStyle(R.style.CustomShowcaseTheme2)
                        .replaceEndButton(button)
                        .setTarget(target)
                        .withMaterialShowcase()
                        .setContentTitle("QR Scan(Required)")
                        .setContentText("Please press the QR icon to scan the QR")
                        .build();

and this is my xml :

<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=".Fragments.QRFragment">


    <ImageView
        android:id="@+id/iv_QR"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_centerHorizontal="true"
        android:layout_centerVertical="true"
        android:background="@mipmap/qricon" />
</RelativeLayout>

I am attaching an Image: enter image description here

Maxim Toyberman
  • 1,906
  • 1
  • 20
  • 35

1 Answers1

0

So assuming that the problem is caused by the ShowcaseView being created before onCreateView() has returned, consider creating and showing your ShowcaseView in the onActivityCreated() method of your Fragment.

Here is some sample code of ShowcaseView being used with Fragments, try to implement it in your own code. As you can see it also uses the method onActivityCreated().

REG1
  • 486
  • 4
  • 15
  • unfortunately it doesn't help even when i have the view @REG1 – Maxim Toyberman Jun 21 '16 at 09:41
  • Can you post more code (including the updates), i.e. show the entire method from which you instantiate the ShowcaseView and all other code related to it? – REG1 Jun 21 '16 at 09:52
  • Thats a lot of code,i will try to explain my self better:I use AppIntro with 3 Fragments ,I use show case with the first fragment and everything is ok there,when I am done with the first Fragment I want to move to next Fragment (the one you see in the picture) ,the problem when Using onActivityCreated() It shows the showcase immediately ,because showcase.build() displays it .now The showcases are one on the other @REG1 – Maxim Toyberman Jun 21 '16 at 12:20
  • So when do you want the showcase to be shown? Are you saying that the "no centered" problem is resolved using onActivityCreated(), but that the showcase is shown too early? – REG1 Jun 21 '16 at 12:49
  • Yes,exactly when the first Fragment is done i want the ShowcaseView to be shown @REG1 – Maxim Toyberman Jun 21 '16 at 12:52
  • @Maximtoyberman So place the `showcase.build()` method into the `onSlideChanged()` method of your `AppIntro` class. This will mean the the showcase is only shown when you select the desired fragment. – REG1 Jun 21 '16 at 13:00
  • Let us [continue this discussion in chat](http://chat.stackoverflow.com/rooms/115223/discussion-between-maxim-toyberman-and-reg1). – Maxim Toyberman Jun 21 '16 at 16:34