【问题标题】:ImageButton Android with ScaleType带有 ScaleType 的 ImageButton Android
【发布时间】:2013-06-24 14:43:31
【问题描述】:

我尝试在我的Activity 中动态编码这个ImageButton,但它看起来非常不同。 ScaleType 似乎不起作用。这是ImageButton 我想要的方式:

     <ImageButton
            android:id="@+id/imageButton1"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:adjustViewBounds="true"
            android:background="@null"
            android:scaleType="fitStart"
            android:src="@drawable/rot" />

这里是我的 Java 代码,用于在我的活动中生成它:

ImageButton field = new ImageButton(this);
                LayoutParams param = new linearLayout.LayoutParams(LayoutParams.WRAP_CONTENT,LayoutParams.WRAP_CONTENT, 1.0f);
                field.setLayoutParams(param);
                field.setScaleType(ScaleType.FIT_START);
                field.setBackgroundResource(0);
                field.setAdjustViewBounds(true);
                field.setImageResource(R.drawable.rot);

有人看到我的错误吗?谢谢!

【问题讨论】:

  • 图片来源不同。由于您使用的是WRAP_CONTENT,可能会导致它的大小不同。
  • 图片来源只是一个例子
  • 当我将 WRAP_CONTENT 更改为 MATCH_PARENT 时,它不会改变任何东西。他完全忽略了“setScaleType”。

标签: android imagebutton


【解决方案1】:

将 ImageButtons 的宽度设置为 fill_parent 并使用 scaletype fitStart 用于紧靠左边距的图像,使用 fitEnd 用于右边的图像。至少就您的示例图像而言,应该做到这一点。如果图像的比例宽度超过屏幕宽度,您可能会遇到一些间距问题,但它应该适合您。

【讨论】:

    猜你喜欢
    • 2023-03-15
    • 2011-09-28
    • 1970-01-01
    • 2011-03-14
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多