I am trying to use setActionView from ActionBar in ICS
It seems like it should be straightforward, but somehow I don't get the layout alignment that I hope for. As you can see in the image below, the target icon is in the right direction inside the layout. But when I setActionBar (progress), the progress view always aligns to the right, no matter what I try.


Here are 2 states, before and after clicking on a menu item. As you can see, viewing progress is always aligned to the right. I tried changing the gravity parameters in my xml progress layout from left to right to the center, and all I can change seems to be changing nothing.
I did not find any information about this problem, so I think I should be doing something wrong.
- ?
!
"action_bar_menu.xml"
<?xml version="1.0" encoding="utf-8"?>
<menu xmlns:android="http://schemas.android.com/apk/res/android">
<item android:id="@+id/locate"
android:title="locate"
android:icon="@drawable/locate"
android:showAsAction="ifRoom|withText" />
</menu>
progressbar 'inderterminate_progress.xml'
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:gravity="center">
<ProgressBar android:layout_width="25dp"
android:layout_height="25dp"
android:layout_gravity="center"
android:indeterminate="true"
style="?android:attr/progressBarStyleInverse"/>
</FrameLayout>
, , testx Activity
public class HelloAndroidActivity extends Activity {
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
getActionBar().setTitle("Test");
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
getMenuInflater().inflate(R.menu.action_bar_menu, menu);
return true;
}
@Override
public boolean onOptionsItemSelected(MenuItem item) {
super.onOptionsItemSelected(item);
if (R.id.locate == item.getItemId()) {
final MenuItem menuItem = item.setActionView(R.layout.inderterminate_progress);
new Thread(new Runnable() {
@Override
public void run() {
SystemClock.sleep(3000);
runOnUiThread(new Runnable() {
@Override
public void run() {
menuItem.setActionView(null);
}
});
}
}).start();
}
return true;
}
}