Android Imagebuttons not aligned as expected
I have a horizontal linear layout with four image buttons. Each image button has an image that is 64x64 pix and button's layout width is set at .25.
The images show up inside the button, but it is offset by a few pixels First button, aligned perfectly in the center Second button, offset towards the right Third button, further offset towards the right Fourth button, further offset and half the image flows outside of the button.I'm writing this based off of some other sample code where it was displayed perfectly. Any thoughts on what could be causing the issue?
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="horizontal" android:layout_width="match_parent"
android:layout_height="wrap_content" android:layout_weight="0">
<ImageButton android:src="@d开发者_StackOverflowrawable/bt1"
android:id="@+id/bt1" android:layout_width="match_parent"
android:layout_weight=".25" android:layout_height="wrap_content"/>
<ImageButton android:id="@+id/bt2"
android:layout_height="wrap_content" android:layout_width="match_parent"
android:layout_weight=".25" android:src="@drawable/bt2"/>
<ImageButton android:id="@+id/bt3"
android:layout_height="wrap_content" android:layout_width="match_parent"
android:layout_weight=".25" android:src="@drawable/bt3"/>
<ImageButton android:id="@+id/bt4"
android:layout_height="wrap_content" android:layout_width="match_parent"
android:src="@drawable/bt4" android:layout_weight="0.25"/>
</LinearLayout>
The styling is done like this:
<item name="android:gravity">center</item>
<item name="android:layout_width">wrap_content</item>
<item name="android:layout_height">wrap_content</item>
You can try to set android:background="@null"
as that often causes some extra width caused by the ImageButton
Try by changing this line android:src
to this android:background
this may be help you.
精彩评论