I have the following code. There's is some preexisting code and I added new changes below. However, I see that in my button, there's some padding on top and bottom. I'm not sure where this is coming from.
class MyButton(context: Context) : Button(context) {
fun init() {
setBackgroundColor(Color.parseColor("#880808")) // for testing
text = context.getString(R.string.some_text)
setTextColor(ContextCompat.getColor(context, R.color.some_color))
this.setTextSize(
TypedValue.COMPLEX_UNIT_DIP, getSizeInDP()
)
//My new changes below
isAllCaps = false
layoutParams = LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT).also {
it.addRule(RelativeLayout.ALIGN_PARENT_BOTTOM)
it.setMargins(getMarginSize(), getMarginSize(), getMarginSize(), getMarginSize())
}
minWidth = 0
minHeight = 0
setPadding(0, 0, 0, 0)
}
// Pre-existed code
class SomeActivity() {
override fun onCreate(savedInstanceState: Bundle?) {
.....
val height = (displayMetrics.heightPixels * 0.15).toInt()
val container = RelativeLayout(this)
val button = MyButton(this)
button.init()
container.addView(button)
container.setBackgroundColor(Color.TRANSPARENT)
val myLayoutParams = createContainerLayoutParams(ViewGroup.LayoutParams.MATCH_PARENT,
headerHeight - 30)
myLayoutParams.topMargin = 30
container.layoutParams = myLayoutParams
.....
}
}
The button has some padding on the top and bottom. I'm not sure where this padding is coming from when I set padding to 0.