i am having a problem with my imagebutton it does not align right when i specify the centerinparent.
<LinearLayout
android:layout_width="match_parent" android:layout_marginTop="4dp"
android:layout_marginLeft="4dp" android:layout_marginRight="4dp"
android:layout_height="50dp" android:background="#FF0000">
<RelativeLayout android:layout_height="match_parent"
android:layout_width="40dp" android:background="#0000FF">
<ImageView android:id="@+id/imgType"
android:layout_centerInParent="true" android:layout_width="wrap_content"
android:src="@drawable/type_text" android:layout_height="wrap_content" />
</RelativeLayout>
<RelativeLayout android:layout_height="match_parent"
android:layout_width="match_parent" android:layout_weight="1">
<LinearLayout android:orientation="vertical"
android:layout_height="match_parent" android:layout_width="match_parent">
<TextView android:layout_width="match_parent"
android:textColor="#686a68" android:layout_height="match_parent"
android:textSize="15dp" android:text="Manifest : Text"
android:ellipsize="end" android:singleLine="true"
android:layout_weight="1" />
<TextView android:layout_width="match_parent"
android:textColor="#686a68" android:layout_height="match_parent"
android:textSize="15dp" android:id="@+id/txtTitle" android:text="[TEXT NAME]"
android:layout_weight="1" android:singleLine="true"
android:ellipsize="end" />
</LinearLayout>
</RelativeLayout>
<RelativeLayout android:layout_height="match_parent"
android:layout_width="60dp" android:background="#00FF00">
<ImageButton android:src="@drawable/type_text"
android:layout_height="48dp" android:layout_centerInParent="true"
android:layout_width="48dp" android:id="@+id/butEdit" />
</RelativeLayout>
</LinearLayout>
As you can see the vertical alignment of the imagebutton is not right.
why is it doing this.
Have you tried running this on the emulator and using the hierarchyviewer tool (in the “tools” folder of the SDK. Click on your app in the list and select “Load View Hierarchy” ) to inspect the elements in question? Have a look at the margins and padding of both the problem control & its container. Also look at the widths of the various components and it may give you a clue as to where the problem is occurring.
Also check that your drawable in @drawable/type_text does not contain any space around it which could be causing a perceived offset (unlikely, I think).
I have occasionally seen odd problems scaling images, so if @drawable/type_text is not 48×48 pixels, try manually scaling the image to the desired size in Photoshop / GIMP / PSP and see if that makes a difference.
Alternatively try using gravity to try to centre your control:
Or maybe:
If all else fails, try tweaking the individual android:layout_margin* attributes of the ImageButton to try and force things.
I hope that some of this helps.