I am building a XML layout for a piano keyboard, based on ImageButtons. The problem gets summarized with the following image:
I am aware that other similar questions have been posted, like this one. However, my approach disagrees with depending on Java to draw layouts, because I think, whenever possible, design issues should depend only on XML. There's also someone offering a template for a piano layout, but I prefer to do my own one.
That said, the point is: Is it possible to make the ImageButtons shown above "overlap" on purpose for making the black keys fit like they should, without depending on Java logic to achieve it? If not, is there a way to customize ImageButton objects to have a shape different than rectangular?
Here's the XML source, summarized:
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:orientation="horizontal"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
android:paddingBottom="@dimen/activity_vertical_margin"
tools:context=".MainActivity">
<!-- first white key -->
<ImageButton
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="@null"
android:id="@+id/ck"
android:src="@drawable/wk_c" />
<!-- the BLACK key -->
<ImageButton
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="@null"
android:id="@+id/bk1"
android:src="@drawable/bk" />
<!-- next white key -->
<ImageButton
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="@null"
android:id="@+id/dk"
android:src="@drawable/wk_d"
android:adjustViewBounds="false" />
<!-- ... and so on for the other keys -->
</LinearLayout>