是否可以在不适合设备视图的情况下以 android 显示原始图像?
Is it possible to display original image in android without fit to device views?
我有一张尺寸为 1000px*1200px 的图片,我希望它在不缩放的情况下显示!
我在 stackover flow 中搜索过,google 我没有找到合适的。
我想要没有缩放的完整图像,
我试过这样
第一步:-
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@drawable/image"
/>
第二步:-
我也试过scaleType
将 scaleType 添加到您的 ImageView
<ImageView
android:scaleType="center"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@drawable/image" />
但这也行不通,
在 sclate 类型中,我尝试了所有可能的属性(矩阵、fitXY 等)。
有没有办法在android中显示原图?
请帮我解决这个问题
您可以尝试这种方法,首先从 drawable 中获取图像并创建位图 it.Then 获取位图的宽度和高度,调整图像视图的大小,然后在 it.It 中显示图像将创建图像视图使用您的原始图片大小。
见下面代码-
BitmapDrawable bitmap = (BitmapDrawable) this.getResources().getDrawable(R.drawable.icon);
int bitmapHeight= bitmap .getBitmap().getHeight();
int bitmapWidth = bitmap .getBitmap().getWidth();
现在你有了原始图像的尺寸。
调整图像视图的大小 -
ImageView imageView = (ImageView) findViewById(R.id.my_image_view);
imageView.getLayoutParams().height = bitmapHeight;
imageView.getLayoutParams().width = bitmapWidth;
并在最后一步中将位图设置为您的图像视图 -
imageView.setImageBitmap(bitmap);
希望对您有所帮助。
已编辑
调整图像视图大小后使用以下代码 -
replace - `imageView.setImageBitmap(bitmap);`
来自
imageView.setImageResource(R.drawable.icon);
根据您的意见,我认为您需要的是像PhotoView这样的库。希望它可以帮助您
虽然我会强烈谴责这样的用户体验,但任何适合你的都行。
1) 用下面的link做一个二维卷轴。
Two dimensional scrolling... a suggestion that needs feedback
2) 添加一个图像视图并在运行时以 px 为单位设置图像视图的图像尺寸。
据我了解,您的问题是您想要图像的自然大小,而不需要 ImageView 标签对其进行修改。这对我有用
<LinearLayout
android:id="@+id/background"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@drawable/image_here"
android:orientation="horizontal|vertical"/>
在评论中告诉我。
使图像布局的宽度和高度能够包裹内容。使 scaleType 居中。通过设备管理器检查您的设备宽度和高度,然后以 %
为单位提供图像高度和宽度
经过多次尝试,我找到了上述问题的解决方案。
代码如下:
主要活动:-
public class MainActivity extends ActionBarActivity {
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
ImageView imageView = (ImageView) this.findViewById(R.id.imageview);
}
}
activity_main.xml:-
<?xml version="1.0" encoding="utf-8"?>
<ScrollView android:id="@+id/ScrollView02"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:scrollbars="none"
xmlns:android="http://schemas.android.com/apk/res/android">
<HorizontalScrollView android:id="@+id/HorizontalScrollView01"
android:layout_width="wrap_content"
android:layout_height="wrap_content">
<ImageView android:id="@+id/imageview"
android:src="@drawable/desert"
android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:adjustViewBounds="true">
</ImageView>
</HorizontalScrollView>
</ScrollView>
这完全符合我的要求。
希望这对其他人有帮助。
我有一张尺寸为 1000px*1200px 的图片,我希望它在不缩放的情况下显示!
我在 stackover flow 中搜索过,google 我没有找到合适的。
我想要没有缩放的完整图像, 我试过这样
第一步:-
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@drawable/image"
/>
第二步:-
我也试过scaleType 将 scaleType 添加到您的 ImageView
<ImageView
android:scaleType="center"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@drawable/image" />
但这也行不通,
在 sclate 类型中,我尝试了所有可能的属性(矩阵、fitXY 等)。
有没有办法在android中显示原图?
请帮我解决这个问题
您可以尝试这种方法,首先从 drawable 中获取图像并创建位图 it.Then 获取位图的宽度和高度,调整图像视图的大小,然后在 it.It 中显示图像将创建图像视图使用您的原始图片大小。
见下面代码-
BitmapDrawable bitmap = (BitmapDrawable) this.getResources().getDrawable(R.drawable.icon);
int bitmapHeight= bitmap .getBitmap().getHeight();
int bitmapWidth = bitmap .getBitmap().getWidth();
现在你有了原始图像的尺寸。 调整图像视图的大小 -
ImageView imageView = (ImageView) findViewById(R.id.my_image_view);
imageView.getLayoutParams().height = bitmapHeight;
imageView.getLayoutParams().width = bitmapWidth;
并在最后一步中将位图设置为您的图像视图 -
imageView.setImageBitmap(bitmap);
希望对您有所帮助。
已编辑
调整图像视图大小后使用以下代码 -
replace - `imageView.setImageBitmap(bitmap);`
来自
imageView.setImageResource(R.drawable.icon);
根据您的意见,我认为您需要的是像PhotoView这样的库。希望它可以帮助您
虽然我会强烈谴责这样的用户体验,但任何适合你的都行。
1) 用下面的link做一个二维卷轴。 Two dimensional scrolling... a suggestion that needs feedback
2) 添加一个图像视图并在运行时以 px 为单位设置图像视图的图像尺寸。
据我了解,您的问题是您想要图像的自然大小,而不需要 ImageView 标签对其进行修改。这对我有用
<LinearLayout
android:id="@+id/background"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@drawable/image_here"
android:orientation="horizontal|vertical"/>
在评论中告诉我。
使图像布局的宽度和高度能够包裹内容。使 scaleType 居中。通过设备管理器检查您的设备宽度和高度,然后以 %
为单位提供图像高度和宽度经过多次尝试,我找到了上述问题的解决方案。
代码如下:
主要活动:-
public class MainActivity extends ActionBarActivity {
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
ImageView imageView = (ImageView) this.findViewById(R.id.imageview);
}
}
activity_main.xml:-
<?xml version="1.0" encoding="utf-8"?>
<ScrollView android:id="@+id/ScrollView02"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:scrollbars="none"
xmlns:android="http://schemas.android.com/apk/res/android">
<HorizontalScrollView android:id="@+id/HorizontalScrollView01"
android:layout_width="wrap_content"
android:layout_height="wrap_content">
<ImageView android:id="@+id/imageview"
android:src="@drawable/desert"
android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:adjustViewBounds="true">
</ImageView>
</HorizontalScrollView>
</ScrollView>
这完全符合我的要求。
希望这对其他人有帮助。