johnw182
johnw182

Reputation: 1469

Android ImageButton image scaling

I have two ImageButtons in a LinearLayout. The Facebook image is 320x113 and the Google+ image is 325x113 (same height). I want both images to display with an equal height (and the wider image will show wider). But for some reason when displaying, the Google+ button is scaling the size larger. Why? Why I ask you!

<LinearLayout
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:orientation="horizontal"
        android:layout_weight="0"
        android:paddingTop="@dimen/padding_large"
        android:paddingLeft="@dimen/padding_large"
        android:paddingRight="@dimen/padding_large"
        android:paddingBottom="@dimen/padding_large">

        <ImageButton android:id="@+id/btnFBShare"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:visibility="gone"
            android:background="@null"
            android:src="@drawable/fb_share"
            android:contentDescription="Share on Facebook"
            />

        <ImageButton android:id="@+id/btnGPShare"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:visibility="gone"
            android:background="@null"
            android:src="@drawable/gp_share"
            android:contentDescription="Share on Google+" />

        <!--  
            android:layout_weight="1" -->

    </LinearLayout>

enter image description here

Upvotes: 0

Views: 280

Answers (2)

johnw182
johnw182

Reputation: 1469

The problem had something to due with Eclipse caching the image files. The cached versions were not the same size. Cleaning the project forced Eclipse to use the newer (same sized files) from disk.

Upvotes: 0

Mani
Mani

Reputation: 231

Try this.....

weight_sum is total weight for the LinearLayout and Layout_weight is applicable to the child views of LL. sum of weight of child views will be equal to weight_sum specified in LL tag. In bellow two ImageButtons have same weight and sum is equal to total,So two child views will share the total width equally

new snippet

<LinearLayout
    style="?android:attr/buttonBarStyle"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:layout_alignParentRight="true"
    android:orientation="horizontal" >
    <Button
        android:id="@+id/btnFBShare"
        style="?android:attr/buttonBarStyle"
        android:layout_width="0dp"
        android:layout_weight="1"
        android:layout_height="50dp" 
        android:src="@drawable/fb_share"
        android:contentDescription="Share on Facebook"/>
    <Button
        android:id="@+id/btnGPShare"
        style="?android:attr/buttonBarStyle"
        android:layout_width="0dp"
        android:layout_weight="1"
        android:layout_height="50dp"
        android:src="@drawable/gp_share"
        android:contentDescription="Share on Google+"  />
</LinearLayout>

Upvotes: 1

Related Questions