Question: I have a numpy array (data.npy) which stores multiple sample images. I want to view/ save all the images. I have tried following:

```
img_array=np.load('data.npy')
i = 0
while i < len(img_array):
   plt.imshow(img_array[i], cmap='gray')
   plt.show()
   i += 1

```

but this gives an error: 

```
TypeError: Invalid dimensions for image data

```

Answer: 
You can `center-align` the menu items dynamically using `SpannableString` in your activity:

```
int positionOfMenuItem = 0; //or any other postion

MenuItem item = menu.getItem(positionOfMenuItem);

SpannableString s = new SpannableString(settingsItemTitle);

s.setSpan(new AlignmentSpan.Standard(Alignment.ALIGN_CENTER), 0, s.length(), 0);

item.setTitle(s);

```
Kotlin extension:

```
fun Menu.centerTitles() {
    for (i in 0 until size()) {
        val item = getItem(i)
        SpannableString(item.title).also {
            it.setSpan(AlignmentSpan.Standard(Layout.Alignment.ALIGN_CENTER), 0, it.length, 0)
            item.title = it
        }
    }
}

```

Usage:

```
navigationViewMain!!.menu.centerTitles()

```

P.S. It's the improved answer by Heena Arora