标签: android-imageview

ImageView 中的 PNG 有黑色背景

我的图像视图设置为一个 PNG 位图。但问题是透明部分是黑色的。我已经将背景设置为@android:color/transparent 和 #00000000,但它仍然是黑色的。我试图搜索,但没有任何帮助。提前致谢!

这是带有父级的 imageView 的 xml:

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:background="@color/mainbg"
    android:orientation="vertical" >

    <LinearLayout
        android:id="@+id/vbTempLink"
        android:layout_width="match_parent"
        android:layout_height="0dp"
        android:layout_weight="15"
        android:background="@color/mainbg"
        android:orientation="vertical" >

        <LinearLayout
            android:id="@+id/linearLayout1"
            android:layout_width="match_parent"
            android:layout_height="0dp"
            android:layout_marginLeft="20dp"
            android:layout_marginRight="20dp"
            android:layout_weight="10"
            android:gravity="center"
            android:orientation="vertical" >

            <ImageView
                android:id="@+id/tempImage1"
                android:layout_width="match_parent"
                android:layout_height="0dp"
                android:layout_weight="25"
                android:background="@android:color/transparent"
                android:gravity="center"
                android:paddingBottom="5dp"
                android:paddingTop="5dp"
                android:scaleType="fitCenter" />
Run Code Online (Sandbox Code Playgroud)

我用这些代码设置了 png(bg 是字符串):

background.setBackgroundDrawable(bitmapToDrawable((bg)));

public Drawable bitmapToDrawable(String s) {
    Bitmap bitmap = BitmapFactory.decodeFile(path + s);
    Drawable drawable = new BitmapDrawable(getResources(), bitmap);
    return drawable;
}
Run Code Online (Sandbox Code Playgroud)

是的,图像肯定有透明背景。

android android-imageview

2
推荐指数
1
解决办法
8724
查看次数

如何动态更改图像大小

我已经在 xml 文件中定义了 imageview 大小。因此,当图像出现时,它将作为默认值。我根据某些条件显示不同的图像。所以,我需要改变图像的宽度和高度。

xml:

<ImageView
        android:id="@+id/imageView1"
        android:layout_width="100dp"
        android:layout_height="100dp"        
        android:visibility="invisible"  />
Run Code Online (Sandbox Code Playgroud)

爪哇:

if (text.equalsIgnoreCase("y")) {                      
      image.setImageResource(R.drawable.y); 

      }                    
    else if (text.equalsIgnoreCase("z")) {
    image.setImageResource(R.drawable.z); // Here i need to change the width & height of the image
               }
Run Code Online (Sandbox Code Playgroud)

android android-image android-imageview

2
推荐指数
1
解决办法
2123
查看次数

Android - 从 url 获取 drawable 的最快方法是什么?

在我的新闻活动中,我需要从 Web 服务器加载图像以将它们放入ListView. 我找到了很多从 url 加载图像的方法。我发现这个解决方案是最有效的: how to set image from url for imageView

当列表中有 1-4 条新闻时,它工作正常。但是当我加载过去 30 天的新闻时出现问题。我的列表变得很长,即使在 2-3 分钟后图像也没有被加载,尽管我把所有的拇指都设置为 4-5 KB。即使我滚动列表,图像也会再次卸载。

在这张图片中,我在 Genymotion 上测试了该应用程序。我打开活动,选择过去30天的新闻。一切正常,因为我使用虚拟服务器。

但是当我在手机上使用真实服务器进行测试时,问题出现了。有什么最优方法吗?

android listview image android-imageview

2
推荐指数
1
解决办法
966
查看次数

Android - 如何从 s3 下载图像?

我正在阅读 s3 android 指南,并且对如何下载我的文件感到非常困惑。

他们提供以下代码:

TransferObserver observer = transferUtility.download(
  MY_BUCKET,     /* The bucket to download from */
  OBJECT_KEY,    /* The key for the object to download */
  MY_FILE        /* The file to download the object to */
);
Run Code Online (Sandbox Code Playgroud)

那么什么是 MY_FILE?我是否想创建一个本地空文件对象并将其提供给该 transferUtility 下载函数,并将该空文件填充到一次下载中?

而且,当我完成获取文件时,(尤其是图像)我如何使用 glide 或 Picasso 将该文件上传到 imageView 中?

我不确定如何使用 TransferObserver 对象。

希望有人可以提供一个工作示例,请!

干杯!

android amazon-s3 android-imageview picasso

2
推荐指数
1
解决办法
3532
查看次数

Android - 在布局边缘将 ImageView 居中

我正在使用 ConstraintLayout 并且我想将 ImageView居中在布局的边缘,如下图所示:

如何在不使用高程的情况下使用 ConstraintLayout 来实现这一点(我不知道如何在棒棒糖之前的设备中处理高程)。

到目前为止,这是我的代码:

 <?xml version="1.0" encoding="utf-8"?>
<android.support.constraint.ConstraintLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:orientation="vertical"
    android:layout_width="match_parent"
    android:layout_height="300dp"
    app:behavior_hideable="false"
    app:behavior_peekHeight="190dp"
    android:clickable="true"
    android:focusable="true"
    android:background="#eee"
    app:layout_behavior="android.support.design.widget.BottomSheetBehavior"
    android:id="@+id/main_ride_finished_container"
    >


    <de.hdodenhof.circleimageview.CircleImageView
        android:id="@+id/main_driver_enroute_BS_driverImage"
        android:layout_width="70dp"
        android:layout_height="70dp"
        android:src="@color/colorPrimary"
        app:layout_constraintLeft_toLeftOf="parent"
        app:layout_constraintRight_toRightOf="parent"
        android:elevation="3dp"
        />
    <android.support.constraint.ConstraintLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:layout_marginTop="35dp"
        android:background="#FFFFFF"
        >


    </android.support.constraint.ConstraintLayout>


</android.support.constraint.ConstraintLayout>
Run Code Online (Sandbox Code Playgroud)

android android-imageview android-constraintlayout

2
推荐指数
1
解决办法
315
查看次数

是否可以使用滑动库制作背景模糊的图像 centerInside ?

我熟悉glide中的fitcenter和centercrop。但是有可能制作像这样的图像吗

在此输入图像描述

有什么想法可以实现它吗?

android image-scaling android-imageview android-glide

2
推荐指数
1
解决办法
1169
查看次数

ImageView 显示灰色方块而不是图像

在此输入图像描述

我尝试了几种不同的方法,但图像视图仍然只显示灰色方块。我正在 API 17 上进行测试。

以下是我尝试过但未成功的选项:

  • 将 XML 中的 ImageView 配置为:

  • 固定宽度和高度;宽度和高度为wrap_content;宽度为match_parent,高度为wrap_content

  • android:scaleType为“fitXY”和“centerCrop”
  • android:将ViewBounds调整为true | 错误的;

尝试过的图像加载方法:

binding.captcha.setImageBitmap (BitmapFactory.decodeFile (imgFile2.getAbsolutePath ()));
Run Code Online (Sandbox Code Playgroud)

还尝试了这个答案/sf/answers/2508156031/

尝试过滑行:

    Glide.with(this)
    .load (Uri.fromFile (imgFile2))
    .skipMemoryCache (true)
    .diskCacheStrategy (DiskCacheStrategy.NONE)
    .override (150, 150)
    .centerCrop ()
    .into (binding.captcha);
Run Code Online (Sandbox Code Playgroud)

下面的选项是唯一显示图像(在背景中)的选项,但是我想知道可能会发生什么来阻止我使用默认方法显示图像......

    Drawable drawableImage = new BitmapDrawable(BitmapFactory.decodeFile(imgFile2.getAbsolutePath()));
    binding.captcha.setBackgroundDrawable(drawableImage);
Run Code Online (Sandbox Code Playgroud)
  • 笔记:
  • imgFile2 不为空,它是从 SD 卡加载的。
  • imgFile2 显示我是否将其用作背景,因此问题不在于该文件。
  • 这个问题不是简单地用 lib 解决的,我已经在尝试 Glide...但是如果你知道我需要做什么才能让它与 glide 一起工作...
  • 如果重要的话,imageView 位于片段内。

当前的 XML:

        <ImageView
            android:layout_width="150dp"
            android:layout_height="150dp"
            android:layout_centerHorizontal="true"
            android:id="@+id/captcha"/>
Run Code Online (Sandbox Code Playgroud)

android imageview android-imageview android-glide

2
推荐指数
1
解决办法
1819
查看次数

底部带有文本叠加的圆形 Avatar ImageView

我正在尝试创建这个头像图像视图

在此输入图像描述

期望我们选择的图像应该出现在半圆叠加层后面。

这是我的半圆代码:

<shape
xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle">
<solid android:color="@color/dark_grey_alpha"/>
<size
    android:width="88dp"
    android:height="44dp"/>
 <corners
    android:bottomLeftRadius="80dp"
    android:bottomRightRadius="80dp"/>
Run Code Online (Sandbox Code Playgroud)

我正在使用 CircularImageView 库和 glide。我这样加载图像:

@BindingAdapter("imageurl")
public static void avatarimage(ImageView imageView, String url) {
    Context context = imageView.getContext();
    Glide.with(context)
            .load(filePath)
            .apply(new 
         RequestOptions().placeholder(R.drawable.no_pic)
                    .error(R.drawable.no_pic))
            .into(imageView);
}
Run Code Online (Sandbox Code Playgroud)

当我运行该应用程序时,它是这样的:

在此输入图像描述

当我尝试将可绘制对象的高度减小到 24dp 时,它变成了这样:

在此输入图像描述

做这个的最好方式是什么?

由于隐私问题,我无法分享完整的布局。这是图像视图的代码

               <FrameLayout
                android:id="@+id/image_container"
                android:layout_width="wrap_content"
                android:layout_height="match_parent"
                android:layout_gravity="center"
                android:paddingBottom="3dp">

                <de.hdodenhof.circleimageview.CircleImageView
                    android:id="@+id/profile_pic"
                    android:layout_width="88dp"
                    android:layout_height="88dp"
                    android:layout_gravity="center"
                    android:adjustViewBounds="false
                    app:imageurl="@{viewModel.url}" />

                <TextView
                    android:layout_width="88dp"
                    android:layout_height="wrap_content"
                    android:layout_gravity="bottom|center"
                    android:background="@drawable/semi_circle_grey"
                    android:text="Change"
                    android:textAlignment="center"
                    android:textColor="@color/white" />

            </FrameLayout>
Run Code Online (Sandbox Code Playgroud)

android avatar textview android-imageview

2
推荐指数
1
解决办法
2015
查看次数

imageView.getWidth(); 返回屏幕而不是位图宽度

我有一个看起来像这样的imageview

 <ImageView
    android:id="@+id/imageView1"
    android:layout_width="wrap_content"
    android:layout_height="fill_parent"
    android:layout_alignTop="@+id/textView3"
    android:layout_centerHorizontal="true"
    android:layout_marginBottom="80dp"
    android:layout_marginTop="40dp"
    android:onClick="Time"
    android:adjustViewBounds="false"
    android:src="@drawable/ic_launcher" />
Run Code Online (Sandbox Code Playgroud)

我试图通过使用获得图像视图中显示的图像的宽度

ImageView artCover = (ImageView)findViewById(R.id.imageView1);
int coverWidth = artCover.getWidth();
Run Code Online (Sandbox Code Playgroud)

但返回的宽度与屏幕宽度相同而不是图像(当图像宽度小于屏幕宽度时).如果我做

int coverHeight = artCover.getHeight(); 
Run Code Online (Sandbox Code Playgroud)

我得到了正确的图像高度.如何获得显示图像的宽度?

android android-layout android-imageview

1
推荐指数
1
解决办法
2578
查看次数

如何使用本地资源的名称String设置ImageView,避免资源的条件映射

我想以编程方式设置ImageView,将本地资源的名称作为String传递.

通过这种方式清楚地识别出可绘制的内容

 R.drawable.mydrawable_name
Run Code Online (Sandbox Code Playgroud)

如果不在条件开关中映射所有内容,我该如何解决此问题?

我想避免这种形式的东西

if(myString.equal"stringname_1"){
   myImageview.setImageResource( R.drawable.stringname_1);
}
else if(myString.equal"stringname_1")....
etc
Run Code Online (Sandbox Code Playgroud)

android android-imageview android-resources

1
推荐指数
1
解决办法
6186
查看次数