我使用這個代碼:如何設置的Fab按鈕的位置協調員佈局的左側或右側邊緣的Android
fabButton.setOnTouchListener(new View.OnTouchListener() {
float x, y;
@Override
public boolean onTouch(View v, MotionEvent event) {
switch (event.getAction()){
case MotionEvent.ACTION_MOVE:
fabButton.setX(fabButton.getX() + (event.getX() - x));
fabButton.setY(fabButton.getY() + (event.getY() - y));
return true;
case MotionEvent.ACTION_DOWN:
x = event.getX();
y = event.getY();
return true;
}
return false;
}
});
現在我想設置的Fab按鈕的位置,最右邊或左邊協調員佈局的最邊緣。
可能
if (xCoordinate < screen center)
{
align Fab button to the Right screen
}
if (xCoordinate > Screen Center)
{
align Fab button to the left of the screen
}
我不知道如何管理這件事情。按要求----
FloatingActionButton fab = (FloatingActionButton) findViewById(R.id.fab);
CoordinatorLayout.LayoutParams params= (CoordinatorLayout.LayoutParams)
fab.getLayoutParams();
params.anchorGravity = Gravity.BOTTOM | GravityCompat.START;
fab.setLayoutParams(params/);
集開始,結束,頂部,底部:
的可能的複製[設置FAB錨重力動態](HTTPS:/ /stackoverflow.com/questions/38039574/set-fab-anchor-gravity-dynamically) –
沒有不工作 –