Android ShowCaseView的buttonLayoutParams不起作用

前端之家收集整理的这篇文章主要介绍了Android ShowCaseView的buttonLayoutParams不起作用前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
我在我的应用程序中使用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);
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);

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);

这对我有用,希望它对某人有所帮助.

原文链接:https://www.f2er.com/android/317573.html

猜你在找的Android相关文章