【问题标题】:How can I fit an Image into another imageview如何将图像放入另一个图像视图
【发布时间】:2012-10-21 19:24:52
【问题描述】:

我有一个已经从 xml 设置的默认图像的 imageview,我想实际地更改它的图像,以便新图像将缩放到以前的图像大小,两个图像都是四舍五入的。

我在设置新图像之前尝试将 scaleType 属性设置为不同的值,但没有成功。

这是xml:

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent" >


<ImageView
    android:id="@+id/up_right_circle_firstiv"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_centerInParent="true"
    android:scaleType="fitXY"
    android:src="@drawable/circle_medium_up" />

这是活动代码:

public class MainActivity extends Activity {
ImageView middleCircle;
@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);
    middleCircle = (ImageView) findViewById(R.id.up_right_circle_firstiv);
    middleCircle.setImageResource(R.drawable.round_pic_one);
}

}

活动内部。

我已经上传了截图:

http://imgur.com/OM79T

http://imgur.com/G7y3Q

【问题讨论】:

  • 我已经更新了这个问题,同时将 layout_width/height 设置为绝对值也没有用。
  • 是的。他(懒惰的忍者)是对的。向我们展示您的屏幕截图。而且,您是否仅在 XML 布局中使用 imageView。显示完整代码。
  • 检查[这个][1]!这可能是您问题的答案。希望能帮助到你。 [1]:stackoverflow.com/questions/8232608/…
  • 分享你的代码,我们可以开始讨论
  • 我已经编辑了帖子,所以它会显示完整的代码,我已经添加了屏幕截图。

标签: android android-imageview


【解决方案1】:

我找到的解决方案是将 layout_width 和 layout_height 设置为默认大小。

首先我取了原始图像文件的大小,然后我将其转换为 dp。

http://labs.skinkers.com/content/android_dp_px_calculator/

每种分辨率都有不同的图像尺寸。

然后我的 xml 看起来像这样:

<ImageView
android:id="@+id/up_right_circle_firstiv"
android:layout_width="33dp"
android:layout_height="33dp"
android:src="@drawable/circle_medium_up" />

我只更改了每个布局的 dp 值。

我知道这不是最好的解决方案,但它对我有用。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2023-03-10
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-04-27
    • 1970-01-01
    • 2021-12-12
    • 2013-07-15
    相关资源
    最近更新 更多