在imageview的形象契合正确的android [英] Fit Image in imageview correctly in android

查看:151
本文介绍了在imageview的形象契合正确的android的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有超市为图像的标识列表视图。目前,它们不完全居中和失真。请看

I have a list view with logos of supermarkets as images. Currently, they are not centered perfectly and are distorted. Please look at the

下面是我行的项目布局

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

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:orientation="horizontal" android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:background="@drawable/highlight_selector">

    <ImageView
        style="@style/imgPriceStoreLogoSmall"
        android:id="@+id/imgStoreLogo"
        android:src="@drawable/panda_logo"
        />
    <LinearLayout
        android:id="@+id/layoutPriceInfo"
        android:layout_width="0dp"
        android:layout_height="wrap_content"
        android:layout_weight="1"
        android:orientation="vertical" >
            <TextView
                android:id="@+id/lblStoreName"
                style="@style/lblRowProductName"
                android:layout_marginTop="5dp"
                android:textColor="@color/black"
                android:textSize="24sp"
                android:fontFamily="sans-serif-thin"
                android:text="Store Full Name"/>
            <TextView
                android:id="@+id/lblPrice"
                style="@style/lblRowOriginalPrice"
                android:textSize="20sp"
                android:textColor="@color/black"
                android:layout_marginTop="5dp"
                android:text="SAR 16.95"/>
        </LinearLayout>
    <ImageView style="@style/imgRowArrowIcon" />
</LinearLayout>

和我的风格

<style name="imgPriceStoreLogoSmall">
    <item name="android:layout_width">80dp</item>
    <item name="android:layout_height">80dp</item>
    <item name="android:layout_gravity">start</item>
    <item name="android:padding">5dp</item>
    <item name="android:scaleType">fitXY</item>
    <item name="android:contentDescription">@string/app_name</item>
    <item name="android:src">@drawable/no_image</item>
</style>

我不知道的标志图像的实际尺寸,但要调整到适合ImageView的很好。任何帮助是AP preciated。

I do not know the actual sizes of the logo images but want to resize to fit in imageview nicely. Any help is appreciated.

谢谢,
Noorul

Thanks, Noorul

推荐答案

以下code适合图像yoursampleimage如果服务器的图像是如此之大。

The following code fits the image to yoursampleimage if the server image is so big

  <LinearLayout
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:background="@drawable/yousampleimagesizeimage" >

            <ImageView
                android:layout_width="fill_parent"
                android:layout_height="fill_parent"
                android:layout_weight="1"
                android:adjustViewBounds="true"
                android:maxHeight="?android:attr/listPreferredItemHeight"
                android:maxWidth="?android:attr/listPreferredItemHeight"
                android:scaleType="centerCrop"
                android:src="@drawable/serverorDynamicimage" />
        </LinearLayout>

(或)

<RelativeLayout
        android:layout_width="wrap_content"
        android:layout_height="wrap_content" >

        <ImageView
            android:scaleType="centerCrop"
            android:id="@+id/actualimage"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_alignBottom="@+id/sampleimage"
            android:layout_alignLeft="@+id/sampleimage"
            android:layout_alignRight="@+id/sampleimage"
            android:layout_alignTop="@+id/sampleimage"
            android:src="@drawable/actualimage" />

        <ImageView
            android:visibility="invisible"
            android:id="@+id/sampleimage"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:src="@drawable/sampleactualimage" />
    </RelativeLayout>

这篇关于在imageview的形象契合正确的android的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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