0
Hello
I have a Tablelayout created dynamically, and I want to insert a FAB on the screen. The problem is I can’t get the normal alignment in the lower right corner.
Am I missing a parameter? Follow 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.