【问题标题】:How to align the image source within the ImageButton?如何在 ImageButton 中对齐图像源?
【发布时间】:2011-10-05 00:32:54
【问题描述】:

我有一个图像按钮,我想占据设备的整个宽度。我使用的图像src没有按钮那么长。默认似乎是将其与按钮的中心对齐。相反,我想将它对齐到左边。我尝试过使用布局重力,但没有任何反应。

这是代码..

<LinearLayout 
   android:id = "@+id/llRoot"
   android:orientation="vertical"
   android:layout_width="fill_parent" 
   android:layout_height="fill_parent"
   android:layout_gravity="left"  >

    <ImageButton 
    android:id="@+id/ibSend"
    android:layout_gravity="left"
    android:layout_width="fill_parent" 
    android:layout_height="wrap_content"
    android:layout_weight="1" 
    android:src="@drawable/send" >
     </ImageButton>

【问题讨论】:

    标签: android alignment imagebutton


    【解决方案1】:

    好吧,我认为您希望 ImageButton 中的图像向左对齐?然后将其添加到您的 ImageButton 属性中:

    android:scaleType="fitStart"
    

    到此,您的图像在 ImageButton 的左侧对齐。

    【讨论】:

    • 属性名称令人困惑,但 scaleType 中的所有选项都可以让您决定是拉伸图像还是保持原样,还是对齐。
    猜你喜欢
    • 1970-01-01
    • 2014-11-18
    • 1970-01-01
    • 2019-11-04
    • 2017-09-29
    • 2013-04-23
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多