Tru*_*eCH 3 android android-glide
我有 ImageView 的简单布局
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/activity_main"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context="com.example.vbusovikov.glidetest.MainActivity">
<ImageView
android:id="@+id/image"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerInParent="true"
/>
</RelativeLayout>
Run Code Online (Sandbox Code Playgroud)
和简单的 Glide 表达式加载图像到这个 ImageView 只是为了测试 Glide
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
ImageView imageView = (ImageView)findViewById(R.id.image);
Glide.with(this)
.load("http://you-ps.ru/uploads/posts/2013-08/1376601606_1273.png")
.error(R.mipmap.ic_launcher)
.into(imageView);
}
Run Code Online (Sandbox Code Playgroud)
但是,会显示错误图标。它可能是什么问题?我的网络上有代理服务器,并且有适合这种情况的 gradle.properties。
systemProp.http.proxyHost=proxy******.ru
systemProp.http.proxyPort=****
Run Code Online (Sandbox Code Playgroud)
但即使我尝试在任何代理之外启动这个小应用程序,它也不会出于某种原因工作。
我的 build.gradle 文件
apply plugin: 'com.android.application'
android {
compileSdkVersion 25
buildToolsVersion "25.0.2"
defaultConfig {
applicationId "com.example.vbusovikov.glidetest"
minSdkVersion 15
targetSdkVersion 25
versionCode 1
versionName "1.0"
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
}
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2', {
exclude group: 'com.android.support', module: 'support-annotations'
})
compile 'com.android.support:appcompat-v7:25.1.1'
compile 'com.github.bumptech.glide:glide:3.7.0'
testCompile 'junit:junit:4.12'
}
Run Code Online (Sandbox Code Playgroud)
更新。这个简单的应用程序可以从互联网加载图片,但不能从我的服务器加载图片。我的服务器的一些图片可以正常加载,但其他图片却没有。我已经迷失了
不幸的是,所有答案都是正确的,但在我的条件下不起作用。服务器设置不适合从中下载图片。
==更新==
后来我想通了,我服务器上的图片坏了。您可以通过在 Mozilla Firefox 中打开此 url 来检查您在提供的 url 上的图片是否有效。图片中的最后几 KB 可能会被删除,但谷歌浏览器等浏览器会忽略它并正常显示图像。但是,Firefox 更敏感,因此有助于定位问题。
==更新2==
又过了一段时间,我发现不仅损坏的图片会导致问题。尝试android:usesCleartextTraffic="true"在应用程序中添加清单。它将解决图片加载的一些问题
| 归档时间: |
|
| 查看次数: |
14323 次 |
| 最近记录: |