I've come across an issue that I can not find a solution. I have a circle layout which I set a random colour as background. The problem is, the layout is square instead of a circle shape. Here is my code:
The oval shape in res/drawable
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="oval">
<size
android:width="@dimen/avatar_height"
android:height="@dimen/avatar_height" />
</shape>
the array of colours which sits in drawable/values/colors
<integer-array name="avatar_colors">
<item>@color/avatar_1</item>
<item>@color/avatar_2</item>
<item>@color/avatar_3</item>
<item>@color/avatar_4</item>
</integer-array>
This is my circle layout
<RelativeLayout
android:id="@+id/letter_avatar"
android:layout_width="@dimen/avatar_height"
android:layout_height="@dimen/avatar_height"
android:background="@drawable/avatar">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textSize="@dimen/textsize_splash_screen"
android:textColor="@color/jwhite"
android:layout_marginBottom="@dimen/gap_small"
android:text="A"
android:layout_centerInParent="true"/>
</RelativeLayout>
and this is how I set the random colour as a background
mLetterAvatar = (RelativeLayout) findViewById(R.id.letter_avatar);
int[] androidColors = getResources().getIntArray(R.array.avatar_colors);
int randomAndroidColor = androidColors[new Random().nextInt(androidColors.length)];
mLetterAvatar.setBackgroundColor(randomAndroidColor);
And this is the result I'm getting
Note: If I don't set the background programatically the layout has a circle shape (see screen-shot below)
How can I get the circle layout and have the option to add a colour as a background programatically? Thank you.