【问题标题】:ShowcaseView is not centeredShowcaseView 未居中
【发布时间】:2016-06-20 11:50:24
【问题描述】:

退出应用程序并重新进入时出现一个奇怪的错误,ShowcaseView 未居中,我在片段中使用此代码。 这是我的代码:

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();

这是我的 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>

我附上一张图片:

【问题讨论】:

  • 您是否在您的RelativeLayout 中尝试过android:gravity="center"?在这种情况下,您可以删除 android:layout_centerHorizontallayout_ centerVertical
  • 它没有帮助@REG1
  • 当应用程序第一次启动时它是居中的,但是当我退出它并再次输入它时会发生这个问题
  • 我发现问题出在哪里,我有时会尝试在 onCreateView 之前显示它,我会在某个事件发生时显示它,我需要考虑在调用 onCreateView 之后如何显示它@REG1
  • 所以我根据你的发现更新了我的答案。

标签: android showcaseview


【解决方案1】:

因此,假设问题是由在 onCreateView() 返回之前创建的 ShowcaseView 引起的,请考虑在 Fragment 的 onActivityCreated() 方法中创建并显示您的 ShowcaseView

Here is some sample code of ShowcaseView 与 Fragments 一起使用,请尝试在您自己的代码中实现它。如你所见,它也使用了onActivityCreated()的方法。

【讨论】:

  • 不幸的是,即使我有 @REG1 的视图,它也无济于事
  • 您能否发布更多代码(包括更新),即显示您实例化 ShowcaseView 的整个方法以及与之相关的所有其他代码?
  • 那是很多代码,我会尝试更好地解释我自己:我使用带有 3 个片段的 AppIntro,我使用第一个片段的展示案例,一切都很好,当我完成第一个 Fragment 我想移到下一个 Fragment (你在图片中看到的那个),使用 onActivityCreated() 时的问题 它立即显示展示柜,因为展示柜.build() 显示它。现在展示柜是一个在另一个上@ REG1
  • 那么您希望什么时候展示展示柜?您是说使用 onActivityCreated() 解决了“不居中”的问题,但是展示展示得太早了吗?
  • 是的,正是当第一个片段完成时,我希望 ShowcaseView 显示 @REG1
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2015-05-25
相关资源
最近更新 更多