The first thing I can fix is to try to install
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="wrap_content" android:layout_height="match_parent" android:layout_gravity="right" >
to your RelativeLayout . Since by default in Android each view is added from left to right (unless you specify something else in your code).
And if that doesn't work, I would add android:layout_width="90dip" or some other value depending on the image and your tests. The second option is more like a workaround, but I think it will work on all devices.
Edit:
As I found, there is a small problem using RelativeLayout and custom views in ActionBar, so it is better to use LinearLayout and set LayoutParams through code. Modify your xml so it looks like this:
<?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="wrap_content" android:layout_height="wrap_content" > <ImageView android:layout_width="wrap_content" android:layout_height="wrap_content" android:src="@drawable/asus" /> </LinearLayout >
and in your MainActivity.class use this:
import com.actionbarsherlock.app.ActionBar.LayoutParams; .... ActionBar actionBar = getSupportActionBar(); actionBar.setTitle("OMG"); LayoutParams lp = new LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT, Gravity.RIGHT | Gravity.CENTER_VERTICAL); View customNav = LayoutInflater.from(this).inflate(R.layout.img, null); // layout which contains your button. actionBar.setCustomView(customNav, lp); actionBar.setDisplayShowCustomEnabled(true);
hardartcore May 13 '13 at 8:06 2013-05-13 08:06
source share