【问题标题】:How to use ShowcaseView with GridView or ListView如何将 ShowcaseView 与 GridView 或 ListView 一起使用
【发布时间】:2014-04-17 06:41:36
【问题描述】:

ShowcaseView(库)如何与 GridView 或 ListView 一起使用?

图书馆是https://github.com/amlcurran/ShowcaseView

【问题讨论】:

    标签: android showcaseview


    【解决方案1】:

    对于那些有同样问题的人,我刚刚找到了一个很好的解决方案:

    showcaseView = new ShowcaseView.Builder(getActivity(),true)
        .setTarget(new ViewTarget(myListView.getChildAt(0).findViewById(R.id.itemIcon)))
        .setStyle(R.style.CustomShowcaseTheme)
        .setContentTitle("My test")
        .setContentText("I love fries")
        .setOnClickListener(new View.OnClickListener() {
             ...
         }
    

    好吧,你用getChildAt(0) 得到你想要的元素,然后在上面写一个findViewById

    不需要创建任何其他视图!

    【讨论】:

    • 如何在回收站视图中获取视图?
    【解决方案2】:

    你可以试试这样的:

    在您的布局中,您可以在要显示的元素上放置一个不可见的按钮

    <Button
        android:id="@+id/showcase_button"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_marginTop="140dp"
        android:visibility="invisible"
        android:text="Showcase" />
    

    然后简单地将该元素设置为目标

    ViewTarget target = new ViewTarget(R.id.showcase_button, this);
    
    new ShowcaseView.Builder(this)
                    .setTarget(target)
                    .setContentTitle("Choose smthn")
                    .setContentText("Some other information can be here.")
                    .hideOnTouchOutside()
                    .build();
    

    【讨论】:

      【解决方案3】:

      当在片段中使用时,尤其是对于 ListViews,你应该像这样使用它:

      fragmentView.post(new Runnable() {
              @Override
              public void run() {
              final View listViewIdentity = infoListView.getChildAt(0);
                  new GuideView.Builder(getContext())
                          .setTitle("Deneme")
                          .setContentText("Deneme 1 2")
                          .setTargetView(listViewIdentity)
                          .setDismissType(GuideView.DismissType.outside)
                          .build()
                          .show();
              }
          });
      

      因为您必须在 onCreate 方法中编写此块,并且在创建 fragmentView 时,ListView 可能还没有准备好。

      这个代码块获取一个特定的单元格并在其上使用展示视图。

      此处的 GuideView 来自您可以在以下位置找到的库:android-arsenal library。

      我希望这会有所帮助,因为它对我有很大帮助。

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 2011-04-04
        • 1970-01-01
        • 2012-09-12
        • 1970-01-01
        • 2011-03-31
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多