ShowcaseView(库)如何与GridView或ListView一起使用?
图书馆https://github.com/amlcurran/ShowcaseView
对于那些有同样问题的人,我刚刚找到了一个很好的解决方案:
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
!
不需要创建任何其他视图!
您可以尝试以下操作:
在你的布局中,你可以在你想要显示的元素上有一个不可见的按钮
<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();
当在片段中使用时,尤其是对于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可能还没有准备好。
这个代码块得到一个特定的单元格,并在上面使用showcase视图
这里的GuideView来自一个库,你可以在:android兵工厂库中找到。
我希望这对我有帮助,因为它对我帮助很大。