【发布时间】: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_centerHorizontal和layout_ centerVertical。 -
它没有帮助@REG1
-
当应用程序第一次启动时它是居中的,但是当我退出它并再次输入它时会发生这个问题
-
我发现问题出在哪里,我有时会尝试在 onCreateView 之前显示它,我会在某个事件发生时显示它,我需要考虑在调用 onCreateView 之后如何显示它@REG1
-
所以我根据你的发现更新了我的答案。
标签: android showcaseview