android复位机器人图片_图片中的ImageView被拉伸 - 机器人

I am trying to make a small image appear on my screen. I want it to be a small square. With the below code, it shows up as a long flat rectangle. I have attached a picture of what it looks like below.

java code

ImageView q1Image = (ImageView)findViewById(R.id.q1Image);

q1Image.setScaleType(ScaleType.FIT_XY);

xml code

android:id="@+id/row4"

android:layout_width="0dip"

android:layout_height="wrap_content"

android:layout_weight="1" >

android:id="@+id/q1Image"

android:layout_width="10dp"

android:layout_height="10dp"

android:layout_weight=".1"

android:textSize="8sp"

android:gravity="center_horizontal" />

EDIT

If I make the width and height equal to 50dp each, the image gets bigger but is still a flat looking rectangle.

解决方案

FIT_XY will stretch your image to fit all yout ImageView.

Use scale type fitCenter to preserve aspect ratio by placing the image in center if your ImageView

q1Image.setScaleType(ScaleType.FIT_CENTER);

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值