【问题标题】:How to show a floating message with a help message to the user如何向用户显示带有帮助消息的浮动消息
【发布时间】:2016-08-24 09:46:25
【问题描述】:

我修改了我的应用程序,即将应用程序的样式从可扩展的 lisview 更改为将其内容显示到带有 pagetitlestrip 的 viewpager。现在我的应用更可爱了,但自从我的新更新发布以来,卸载量增加了很多。

我很确定用户正在卸载我的应用,因为他们不知道必须向左滑动才能看到应用的下一个内容。

所以我认为我需要为用户添加一些帮助。我想到了一个向右箭头的浮动图像视图,并带有一条消息,显示文本“向右移动以查看更多内容”和一个关闭按钮。

实现这一目标的最佳策略是什么?谁应该使用一些 xml 技巧?还是应该由java代码完成?任何示例代码都会很棒。

这是我的 xml 布局:

<?xml version="1.0" encoding="utf-8"?>
<android.support.v4.widget.DrawerLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:id="@+id/drawer_layout"
    android:layout_width="match_parent"
    android:layout_height="match_parent">
    <!-- The main content view -->
    <RelativeLayout
        android:id="@+id/main_layout"
        android:layout_width="match_parent"
        android:layout_height="match_parent">
        <android.support.v4.view.ViewPager
            xmlns:android="http://schemas.android.com/apk/res/android"
            android:id="@+id/pager"
            android:layout_width="match_parent"
            android:layout_height="match_parent">
            <android.support.v4.view.PagerTitleStrip
                android:id="@+id/pager_title_strip"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:layout_gravity="top"
                android:paddingTop="4dp"
                android:paddingBottom="4dp"
                style="@style/CustomPagerTitleStrip"/>
        </android.support.v4.view.ViewPager>
    </RelativeLayout>
    <!-- The navigation drawer -->
    <android.support.design.widget.NavigationView
        android:id="@+id/navigation_view"
        android:layout_width="wrap_content"
        android:layout_height="match_parent"
        android:layout_gravity="start"
        android:fitsSystemWindows="true"
        app:headerLayout="@layout/drawer_header"
        app:menu="@menu/drawer_menu"
        style="@style/NavigationDrawerStyle"/>
</android.support.v4.widget.DrawerLayout>

【问题讨论】:

  • 你可以试试这样的:github.com/amlcurran/ShowcaseView
  • @Opoo 我更喜欢在我的应用中添加一个小代码而不是第三方库,但是谢谢
  • @Opoo 我正在尝试您的建议,但似乎不能与使用 AppCompatActivity 的较新项目一起使用,我收到此错误:java.lang.RuntimeException: insertShowcaseViewWithType cannot be used when the theme没有ActionBar
  • 真可惜。显然他们并没有很好地维护它。也许手动解决方案会起作用。

标签: android android-layout android-viewpager android-animation android-xml


【解决方案1】:

一个简单的解决方案是这样的:

<RelativeLayout
    android:id="@+id/main_layout"
    android:layout_width="match_parent"
    android:layout_height="match_parent">
    <android.support.v4.view.ViewPager
        xmlns:android="http://schemas.android.com/apk/res/android"
        android:id="@+id/pager"
        android:layout_width="match_parent"
        android:layout_height="match_parent">
        <android.support.v4.view.PagerTitleStrip
            android:id="@+id/pager_title_strip"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_gravity="top"
            android:paddingTop="4dp"
            android:paddingBottom="4dp"
            style="@style/CustomPagerTitleStrip"/>
    </android.support.v4.view.ViewPager>
    <RelativeLayout
        visibility="gone"
        ...>
        <ImageView.../>
        <Button.../> -->dismiss
    </RelativeLayout>
</RelativeLayout>

取决于或您是否已经显示它(保存在 SharedPreferences 或数据库中),您会显示它。您必须在 viewpager xml 下方添加叠加层的 xml,因为 xml 是自上而下解析的。

【讨论】:

  • 如果我这样做,帮助布局将位于 viewpager 下方,并且应该浮动在屏幕中间。顺便说一句,我的 cmets 关于您的第三方提案的问题,我正在尝试,但我遇到了问题
  • 它将位于 ViewPager 的顶部,因为在 RelativeLayout 中,xml 中的最低布局将绘制在顶部(如果您尚未设置任何相对定位)。如果你给你的 RelativeLayout 一个透明的背景,并在 relativelayout 中将你的 imageview 居中,它看起来像浮动的吗?
  • 我成功地从您的第三方提案中添加了一个浮动展示视图,但它在我的应用程序底部的 admob 横幅上方放置了“GOT IT”按钮。你知道是否可以改变“GOT IT”的位置吗?我正在使用 SingleShot 展示的构造函数。有很多不同的陈列柜的构造函数。
  • 不完全确定,但您可以在代码中添加 ShowCaseView 并设置上边距?也许这个链接会为你提供一些报道。 novoda.com/blog/…
猜你喜欢
  • 1970-01-01
  • 2019-03-25
  • 2021-09-16
  • 1970-01-01
  • 2015-07-26
  • 2020-03-04
  • 1970-01-01
  • 1970-01-01
  • 2011-11-21
相关资源
最近更新 更多