Android ShowCaseView 的 buttonLayoutParams 不起作用

标签 android showcaseview

我在我的应用程序中使用 ShowCaseView 库。我想将“确定”按钮移到左侧。 我使用了这段代码(在库中相同):

// The following code will reposition the OK button to the left.
RelativeLayout.LayoutParams lps = new RelativeLayout.LayoutParams(
            ViewGroup.LayoutParams.WRAP_CONTENT,
            ViewGroup.LayoutParams.WRAP_CONTENT);
lps.addRule(RelativeLayout.ALIGN_PARENT_BOTTOM);
lps.addRule(RelativeLayout.ALIGN_PARENT_LEFT);
int margin = ((Number) (getResources().getDisplayMetrics().density * 12))
        .intValue();
lps.setMargins(margin, margin, margin, margin);
View showcasedView = findViewById(R.id.ib_next);
ViewTarget target = new ViewTarget(showcasedView);
ShowcaseView.ConfigOptions co = new ShowcaseView.ConfigOptions();
co.buttonLayoutParams = lps;
co.fadeInDuration = 1000;
co.fadeOutDuration = 1000;
ShowcaseView sv = ShowcaseView.insertShowcaseView(target, this,
        R.string.showcase_title, R.string.showcase_details, co);

但是没有效果?谁能告诉我问题出在哪里?

最佳答案

我知道这个问题很老了,但万一有人需要一个可行的解决方案:

RelativeLayout.LayoutParams lps = new RelativeLayout.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT);
// This aligns button to the bottom left side of screen
lps.addRule(RelativeLayout.ALIGN_PARENT_BOTTOM);
lps.addRule(RelativeLayout.ALIGN_PARENT_LEFT);
// Set margins to the button, we add 16dp margins here
int margin = ((Number) (getResources().getDisplayMetrics().density * 16)).intValue();
lps.setMargins(margin, margin, margin, margin);

ViewTarget target = new ViewTarget(R.id.buttonBlocked, this);
sv = new ShowcaseView.Builder(this)
        .withMaterialShowcase()
        .setTarget(target)
        .setContentTitle(R.string.showcase_main_title)
        .setContentText(R.string.showcase_main_message)
        .build();
// Set declared button position to ShowcaseView
sv.setButtonPosition(lps);

这对我有用,希望它能帮助别人。

关于Android ShowCaseView 的 buttonLayoutParams 不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22760522/

相关文章:

Android NDK Eclipse CDT 不允许我使用字符串的 substr 方法

java - 添加 ShowcaseView 作为库项目

android - 如何制作橱窗纯色背景

android - 目标列表的 ShowcaseView ConfigOptions

android - 多个选项的 SQLite 查询帮助

android - java.lang.OutOfMemoryError : bitmap size exceeds VM budget - android - how many images? 错误

android - 在屏幕上显示 Android 应用程序的日志消息

android - 让两个应用程序使用相同的签名相互通信

java - 如何在 Eclipse 中导入 ShowcaseView?

android - 如何在 Android 中创建信息叠加层