Question

I need a layout that distributes 12 round buttons (circles) evenly on the screen.

For the round shape Im using this:

<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="oval" >
<solid android:color="@android:color/darker_gray"/>
</shape>

and as Layouts I use LinearLayouts (width= 0, height=fill and weight=1 for every button).

The problem is I have to set width and heights for the buttons to get a circle instead of a football shape (oval).

Is there a way to set width=height while still fitting different screen sizes?

Was it helpful?

Solution

Give the layout_height & layout_width value in DP. And put your XML in all the folders like layout, layout-large,layout-xlarge.

OTHER TIPS

From xml it wont be possible to set width = height and make it fit for different screen resolutions. But it can be done from the code.

Based on device width, height and density you can calculate your layout.

Something like this:

DisplayMetrics metrics = this.getResources().getDisplayMetrics();
int displayWidth = metrics.widthPixels;
int displayHeight = metrics.heightPixels;

For screen density you can get it by:

int density = metrics.density;
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top