首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >ImageButton安卓与ScaleType

ImageButton安卓与ScaleType
EN

Stack Overflow用户
提问于 2013-06-24 14:43:31
回答 1查看 1.6K关注 0票数 3

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

代码语言:javascript
复制
     <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代码,可以在我的活动中生成这个代码:

代码语言:javascript
复制
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);

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

EN

回答 1

Stack Overflow用户

发布于 2014-12-22 12:18:53

将ImageButtons的宽度设置为fill_parent,并对拥抱左侧边距的图像使用缩放类型fitStart,对右边的图像使用fitEnd。应该能做到这一点,至少就你的例子形象而言。如果图像的比例宽度超过屏幕宽度,您可能会遇到一些间隔问题,但它应该适用于您。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/17278298

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档