广场的ImageView [英] Square ImageView

查看:139
本文介绍了广场的ImageView的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图表现出的ImageView 其形状对话框里总是广场。的尺寸可根据显示的分辨率(宽度在纵向为precise)而变化,但所述的ImageView需要形成最大广场能够容纳一正方形图像在它里面。这是我的XML $ C $下是一样的。

I am trying to show an ImageView which is always square in shape inside a dialog. The dimensions may vary depending upon the resolution of the display(Width in portrait to be precise) but the ImageView is required to form the largest Square possible to accomodate a square image inside it. This is my XML code for the same.

<ImageView
    android:id="@+id/dialog_image"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:scaleType="centerInside"
    android:adjustViewBounds="true"
    />

但问题是,广场图像动态地在运行时设置和ImageView的结束是与广度为正方形图像大小的矩形。我能做些什么来实现相同的?

But the problem is that the Square image is set dynamically at runtime and the ImageView ends up being a rectangle with breadth as the Square Image size. What can i do to achieve the same?

编辑::要举什么,我想实现像当选择在联系人应用程序中的联系人和个人资料图片被点击所显示的想法。它缩小,仍然是在活动的前一个正方形。

To give an idea of what i am trying to achieve is like what is shown when a contact is selected in contacts application and the profile picture is clicked. It zooms out and remains as a square on top of the activity.

推荐答案

在运行时将图像视图高度,但首先获得显示宽度与此code

Set the Image view height at run time but first get the display width with this code

Display  display = getWindowManager().getDefaultDisplay();
int swidth = display.getWidth();

和现在这样设置图像视图的高度

and now set the height of image view like this

LayoutParams params = eventImage.getLayoutParams();
params.width = LayoutParams.FILL_PARENT;
params.height = swidth ;
eventImage.setLayoutParams(params);

这篇关于广场的ImageView的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆