Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/234.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Android 包裹内容图像视图显示图像的完整大小_Android_Image_Imageview_Blur - Fatal编程技术网

Android 包裹内容图像视图显示图像的完整大小

Android 包裹内容图像视图显示图像的完整大小,android,image,imageview,blur,Android,Image,Imageview,Blur,我在android中使用imageview,当我将图像放入imageview时,使用属性wrap\u content表示高度和宽度。图像看起来是如此之大,因为它们是真实的大小,或者如果我拍摄小图像,它们会变得模糊 代码 在imageview上使用固定大小的宽度和高度 <ImageView android:layout_width="200dp" android:layout_height="180dp" android:id="@+id/imageView"

我在android中使用
imageview
,当我将图像放入
imageview
时,使用属性
wrap\u content
表示高度和宽度。图像看起来是如此之大,因为它们是真实的大小,或者如果我拍摄小图像,它们会变得模糊

代码





imageview
上使用固定大小的宽度和高度

<ImageView
    android:layout_width="200dp"
    android:layout_height="180dp"
    android:id="@+id/imageView"
    android:src="@drawable/image"
    android:scaleType="fitXY"/>

图像视图上使用固定大小的宽度和高度

<ImageView
    android:layout_width="200dp"
    android:layout_height="180dp"
    android:id="@+id/imageView"
    android:src="@drawable/image"
    android:scaleType="fitXY"/>

使用LinearyLayout包装您的ImageView和另一个不可见视图,并将布局权重设置为0.3或0.5等,然后ImageView将根据您的大小

下面是一个示例,演示如何将图像设置为屏幕大小的一半

<?xml version="1.0" encoding="utf-8"?>

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
              android:orientation="vertical"
              android:layout_width="match_parent"
              android:layout_height="match_parent">
    <RelativeLayout
        android:layout_width="match_parent"
        android:layout_height="0dp"
        android:layout_weight="0.5"
        android:background="#ff0000"
        >
        <ImageView
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:src="@drawable/your_image"
            android:adjustViewBounds="true"
            />
    </RelativeLayout>
    <View
        android:layout_width="match_parent"
        android:layout_height="0dp"
        android:layout_weight="0.5"
        android:background="#00ff00"
        />
</LinearLayout>


如果您想将图像放在屏幕中央,您可以使用相同的想法并设置适当的权重以实现您的目标

使用LinearyLayout包装您的ImageView和另一个不可见视图,并将布局权重设置为0.3或0.5等,然后ImageView将根据您的大小

下面是一个示例,演示如何将图像设置为屏幕大小的一半

<?xml version="1.0" encoding="utf-8"?>

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
              android:orientation="vertical"
              android:layout_width="match_parent"
              android:layout_height="match_parent">
    <RelativeLayout
        android:layout_width="match_parent"
        android:layout_height="0dp"
        android:layout_weight="0.5"
        android:background="#ff0000"
        >
        <ImageView
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:src="@drawable/your_image"
            android:adjustViewBounds="true"
            />
    </RelativeLayout>
    <View
        android:layout_width="match_parent"
        android:layout_height="0dp"
        android:layout_weight="0.5"
        android:background="#00ff00"
        />
</LinearLayout>


如果你想把你的图像放在屏幕的中央,你可以使用同样的想法并设置适当的权重来实现你的目标

你试过使用
android:scaleType
属性吗

例如:

android:scaleType="centerCrop"

此属性使用许多其他值,如“fitXY”、“center”、“centerInside”等。尝试此属性

是否尝试使用
android:scaleType
属性

例如:

android:scaleType="centerCrop"

此属性使用许多其他值,如“fitXY”、“center”、“centerInside”等。请尝试此属性。您可以通过编程手动指定宽度和高度

<ImageView   android:layout_width="100dp"
android:layout_height="200dp"
android:src="@drawable/notes"
android:id="@+id/iv_notes"
android:scaleType="fitXY"/>

您可以通过编程手动指定宽度和高度

<ImageView   android:layout_width="100dp"
android:layout_height="200dp"
android:src="@drawable/notes"
android:id="@+id/iv_notes"
android:scaleType="fitXY"/>
使用
android:scaleType=“centerInside”
使用
android:scaleType=“centerInside”
在xml中使用src而不是background
请提供xml以了解您是如何实现它的

使用src而不是xml中的后台
请给出xml以查看您是如何实现它的

您使用的代码给出了正确的结果:您使用了LinearLayout并使用了权重。权重将根据屏幕分辨率进行划分。只需删除LinearLayout并使用Relativelayout即可。接下来移除图像的所有权重,并将其属性设置为“包裹内容”。如果你想给你的图像,完全适合你的屏幕宽度做编程

 DisplayMetrics displaymetrics = new DisplayMetrics();
getWindowManager().getDefaultDisplay().getMetrics(displaymetrics);
int height = displaymetrics.heightPixels;
int width = displaymetrics.widthPixels;
int desiredWidth=width/2;
yourView.setHeight(desiredWidth);

如果这不是你的要求,那么在你的相对论中,你有这些图像。给出属性
android:alignParentRight=“true”
用于一幅图像,android:alignParentLeft=“true”
用于另一幅图像并设置边距。

您使用的代码给出了正确的结果:您使用了LinearLayout并使用了权重。权重将根据屏幕分辨率进行划分。只需删除LinearLayout并使用Relativelayout即可。接下来移除图像的所有权重,并将其属性设置为“包裹内容”。如果你想给你的图像,完全适合你的屏幕宽度做编程

 DisplayMetrics displaymetrics = new DisplayMetrics();
getWindowManager().getDefaultDisplay().getMetrics(displaymetrics);
int height = displaymetrics.heightPixels;
int width = displaymetrics.widthPixels;
int desiredWidth=width/2;
yourView.setHeight(desiredWidth);

如果这不是你的要求,那么在你的相对论中,你有这些图像。给出属性
android:alignParentRight=“true”
用于一个和
android:alignParentLeft=“true”
用于另一个图像并设置边距。

根据需要为其提供自定义高度和宽度。提供xml代码。如果要在列表或recyclerview中显示图像,则只需使用75dp*75dp的可能重复项在添加到项目之前检查图像大小,使用小图像作为小尺寸,使用所有可绘制文件夹添加图像,这样你就不会得到模糊的图像。根据你的需要给它定制的高度和宽度。给你的xml代码。如果你想在列表或recyclerview中显示图像,那么只需使用75dp*75dp的可能副本在添加到项目之前检查图像大小,使用小图像作为小尺寸,使用所有可绘制的文件夹添加图像,因此,你不会得到模糊的图像。如果你没有正确的答案,请发表评论如果你没有正确的答案,请发表评论最初我使用了与相对布局相同的方法,但我使用的图像太大,因此我不适合查看,请尝试我告诉你的第二种方法。只需放置包裹内容并进行对齐。最初我使用了与相对布局相同的布局,但我使用的图像太大,因此我不适合查看,所以请尝试我告诉您的第二种方法。只需放置包裹内容并进行对齐即可。