Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android ShowCaseView's buttonLayoutParams won't work

I'm using ShowCaseView library in my app. And I want to move the 'OK' button to the left. I used this code (the same in the library):

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

But it doesn't work? Can anyone tell Where is the problem?

like image 692
Mehrdad Avatar asked Mar 31 '14 11:03

Mehrdad


1 Answers

I know the question is pretty old, but in case someone needs a working solution:

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

This worked for me, hope it helps somebody.

like image 176
Sdghasemi Avatar answered Oct 01 '22 08:10

Sdghasemi