0

I'm creating a simple custom view. My view inherits from AppCompatImageButton with the goal of drawing some simple geometric shapes for my custom button and animating them.

If my XML view contains:

android:background="@color/transparent"

My view draws correctly inside a vertical LinearLayout, even though the android:background seems to otherwise do nothing. However, if I leave out android:background, the top and bottom displays an additional unwanted gap between the custom views.

The documentation says these two are "Related":

View.setBackgroundResource(int resid)

android:background

I've tried calling setBackgroundResource(R.color.transparent) in my Java initialization code, thinking this would do the same thing as XML android:background, but the unwanted padding won't go away. Here's a screenshot that shows the view without the android:background.

enter image description here

With android:background, the image fills the entire height not leaving the gap at the top and bottom.

How can I get my custom view to fill the entire drawing area without forcing an artificial android:background into the XML? The solution will also need to work if the programmer creates the custom view in Java without XML.

Thx.

Mitch
  • 1,716
  • 3
  • 25
  • 41
  • Please attach screenshots – Harsh Patel May 11 '17 at 04:57
  • @BabulPatel, does this help? – Mitch May 11 '17 at 05:23
  • setBackgroundResource(getResources().getColor(R.color.dark_blue))--------------try this. – Harsh Patel May 11 '17 at 05:27
  • @BabuPatel... That doesn't compile, but I've tried similar. setBackgroundResource(R.color.transparent); as already mentioned in my post. No effect. – Mitch May 11 '17 at 06:57
  • I can also inherit from AppCompatImageView to remove the unwanted gap. I'm not super happy with this as a solution as I'd like the user to click the buttons and have the programmer handle the clicks without extra coding on my part. Without a better suggestion, I'll move forward with this option. – Mitch May 11 '17 at 16:15

0 Answers0