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);

```
`android:gravity="center"` sets the gravity of the content of the View its used on.
`android:layout_gravity` sets the gravity of the View or Layout in its parent.