5 android imageview android-glide
我正在尝试从网络下载图像并使用scaleType =“centerInside”选项使用Glide在ImageView中显示。
由于某种原因,从网络下载的图像在屏幕上看起来比从资源放入 ImageView 时小得多。
例子:

两张图片都可以在这里找到。我认为,与我在笔记本电脑上看到的图像相比,即使是从资源设置的图像看起来也比实际大小要小。我知道这与屏幕密度有关,但如何使这些图像具有“用户友好的尺寸”,例如更大一点?
即使是600x250 像素大小的不同图像在手机上也小得离谱(ImageView 的layout_height 和layout_width 设置为“wrap_content”)。

活动代码:
public class DisplayImagesActivity extends AppCompatActivity {
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.display_image_activity);
setSupportActionBar((Toolbar) findViewById(R.id.toolbar));
setTitle("Hello StackOverflow!");
ImageView top_left = (ImageView) findViewById(R.id.top_left);
ImageView top_right = (ImageView) findViewById(R.id.top_right);
ImageView bottom_left = (ImageView) findViewById(R.id.bottom_left);
ImageView bottom_right = (ImageView) findViewById(R.id.bottom_right);
String[] urls = new String[] {
"http://imgur.com/6jMOdg0.png",
"http://imgur.com/AhIziYr.png"
};
top_left.setImageResource(R.drawable.top_left);
top_right.setImageResource(R.drawable.top_right);
Glide.with(this)
.load(urls[0])
.signature(new StringSignature(new Date().toString()))
.into(bottom_left);
Glide.with(this)
.load(urls[1])
.signature(new StringSignature(new Date().toString()))
.into(bottom_right);
}
@Override
public boolean onOptionsItemSelected(MenuItem item) {
switch (item.getItemId()) {
case android.R.id.home:
this.finish();
return true;
default:
return super.onOptionsItemSelected(item);
}
}
}
Run Code Online (Sandbox Code Playgroud)
display_image_activity.xml 文件:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
style="@style/match_parent"
android:orientation="vertical">
<include layout="@layout/_toolbar" />
<ScrollView
style="@style/match_parent">
<RelativeLayout
style="@style/match_parent"
android:padding="16dp">
<TextView
style="@style/wrap_content"
android:id="@+id/text_resources"
android:layout_marginBottom="10dp"
android:text="From Resources"/>
<ImageView
android:id="@+id/top_left"
android:background="@color/Linen"
android:layout_width="150dp"
android:layout_height="120dp"
android:layout_marginBottom="20dp"
android:layout_below="@id/text_resources"
android:scaleType="centerInside"/>
<ImageView
android:id="@+id/top_right"
android:background="@color/Linen"
android:layout_width="150dp"
android:layout_height="120dp"
android:layout_toRightOf="@id/top_left"
android:layout_toEndOf="@id/top_left"
android:layout_below="@id/text_resources"
android:layout_marginLeft="20dp"
android:layout_marginStart="20dp"
android:scaleType="centerInside"/>
<TextView
style="@style/wrap_content"
android:id="@+id/text_network"
android:layout_below="@id/top_left"
android:layout_marginBottom="10dp"
android:text="From Network"/>
<ImageView
android:id="@+id/bottom_left"
android:background="@color/Linen"
android:layout_width="150dp"
android:layout_height="120dp"
android:layout_below="@id/text_network"
android:scaleType="centerInside" />
<ImageView
android:id="@+id/bottom_right"
android:background="@color/Linen"
android:layout_width="150dp"
android:layout_height="120dp"
android:layout_toRightOf="@id/bottom_left"
android:layout_toEndOf="@id/bottom_left"
android:layout_below="@id/text_network"
android:layout_marginLeft="20dp"
android:layout_marginStart="20dp"
android:scaleType="centerInside" />
</RelativeLayout>
</ScrollView>
</LinearLayout>
Run Code Online (Sandbox Code Playgroud)
我遇到了同样的问题。Glide 尝试解释我的应用程序的需求并相应地转换图像,导致某些地方的图像太小。就我而言,ImageViews 使用adjustViewBounds="true"和 MaxWdth/Height 会导致问题
虽然我距离滑翔专家还差得远,但我发现了一个适合我的快速修复方法。
我只是添加了一个.dontTransform()方法调用,在我的情况下这是可以的,因为我使用已经预先缩放的缩略图。
GlideApp.with(context).load(fireStorage).dontTransform().into(imgView);
Run Code Online (Sandbox Code Playgroud)
(使用占位符可能也会有帮助,但对我来说,这是最简单的方法)
您的图像不能大于您定义的大小:
android:layout_width="150dp"
android:layout_height="120dp"
Run Code Online (Sandbox Code Playgroud)
尝试
android:layout_width="match_parent"
android:layout_height="wrap_content"
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
2386 次 |
| 最近记录: |