Answer the question
In order to leave comments, you need to log in
How to make a rounded button in Android (but not rounded corners)?
How to make a rounded button in Android, not with rounded corners, but rounded, as in the screenshot below.
So that, regardless of the height of the content, the sides are rounded (not corners, but sides).
Answer the question
In order to leave comments, you need to log in
I did it via GlobalLayoutListener:
private void addRoundedBackground(final TextView textView, final int color, final int borderColor) {
textView.getViewTreeObserver().addOnGlobalLayoutListener(
new ViewTreeObserver.OnGlobalLayoutListener() {
@Override
public void onGlobalLayout() {
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.JELLY_BEAN) {
textView.getViewTreeObserver().removeGlobalOnLayoutListener(this);
} else {
textView.getViewTreeObserver().removeOnGlobalLayoutListener(this);
}
final float height = textView.getHeight();
GradientDrawable shape = new GradientDrawable();
shape.setCornerRadius(height/2);
shape.setColor(color);
shape.setStroke(1, borderColor);
textView.setBackgroundDrawable(shape);
}
});
}
1) Alternatively, you can draw an oval with canvas ( stackoverflow.com/questions/5012685/draw-an-oval-s... and then overlap top and bottom with two background color views.
2) CardView play around with corner radius
3) change design and not to get tired (is it really necessary?)
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question