Hello
I have a dynamically created TableLayout, and I want to insert an FAB on the screen. The problem is that I can not get the normal alignment in the lower right corner.
Am I forgetting any parameters? Here is the code I'm using:
private FloatingActionButton getFAB() {
FloatingActionButton fab = new FloatingActionButton(this);
CoordinatorLayout.LayoutParams p = new CoordinatorLayout.LayoutParams(
ViewGroup.LayoutParams.WRAP_CONTENT,
ViewGroup.LayoutParams.WRAP_CONTENT
);
p.setAnchorId(R.id.viewpagerOpcao);
p.anchorGravity = Gravity.BOTTOM | Gravity.END | Gravity.RIGHT;
fab.setLayoutParams(p);
fab.setImageDrawable(ContextCompat.getDrawable(this, R.drawable.design_fab_background));
fab.setClipToOutline(true);
fab.setBackgroundTintList(ColorStateList.valueOf(ContextCompat.getColor(this, R.color.colorAccent)));
fab.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Intent criar = new Intent(MainActivity.this, MainOpcao.class);
startActivity(criar);
}
});
To call this method, I do "table.addView (getFAB ());" where table is a TableLayout.