Android ImageButton图像缩放

时间:2014-05-12 01:26:48

标签: android imagebutton scaling

我在LinearLayout中有两个ImageButtons。 Facebook图片为320x113,Google+图片为325x113(相同高度)。我希望两个图像以相同的高度显示(并且更宽的图像将显示更宽)。但由于某些原因,在显示时,Google+按钮会缩小尺寸。为什么?我为什么问你!

<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

2 个答案:

答案 0 :(得分:1)

试试这个......

weight_sum是LinearLayout的总权重,而Layout_weight适用于LL的子视图。 子视图的权重总和将等于LL标记中指定的weight_sum。 在下面两个ImageButton具有相同的权重,总和等于总和,因此两个子视图将共享总宽度

新代码段

<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>

答案 1 :(得分:0)

问题与Eclipse缓存图像文件有关。缓存版本的大小不同。清理项目迫使Eclipse使用磁盘中较新的(相同大小的文件)。