Android url设置setBackground

使用Glide从URL加载图像,Glide是一个快速高效的开源Android媒体管理和图像加载框架,将媒体解码,内存和磁盘缓存以及资源池整合到一个简单易用的界面中。

Glide负责尽可能平滑地滚动任何图像列表,并接收,调整大小和显示远程图像。

添加下面的依赖关系build.gradle

dependencies { 
    compile 'com.github.bumptech.glide:glide:3.6.0' 
    compile 'com.android.support:support-v4:19.1.0' 
} 

如用法:

@Override 
public void onCreate(Bundle savedInstanceState) { 
    ... 

    ImageView imageView = (ImageView) findViewById(R.id.my_image_view); 

    Glide.with(this).load("http://goo.gl/gEgYUd").into(imageView); 
} 

load方法只需传递图像的URL,并在into只是通过视图,在你的情况下currentview。 对于您的场景:

Glide.with(this).load("http://goo.gl/gEgYUd").into(currentView); 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
### 回答1: Android中的setbackground是一个方法,用于设置View或ViewGroup的背景。可以通过传递一个Drawable对象或一个颜色值来设置背景。例如,可以使用以下代码将一个LinearLayout的背景设置为红色: LinearLayout layout = findViewById(R.id.layout); layout.setBackgroundColor(Color.RED); ### 回答2: AndroidsetBackground()方法允许我们改变一个视图的背景,即使用不同的颜色或背景图像将视图的外观设置为不同的样式。 在Android中,setBackground()方法有多种应用,从简单的更改视图背景颜色,到复杂的使用图像作为背景或将多个颜色应用于同一视图。 以下是不同的方法来使用setBackground()方法: 1. 使用颜色设置背景 可以使用设置颜色来设置视图的背景,如下所示: view.setBackgroundColor(Color.RED); 2. 使用drawable设置背景 可使用drawable来设置视图的背景。drawable是可重复使用的图像资源,可以从Android资源文件夹中调用。以下是使用drawable设置背景的示例代码: view.setBackground(getResources().getDrawable(R.drawable.background_image)); 在这个例子中,androidsetBackground()方法使用了getResources().getDrawable() 方法来设置背景图像。 3. 用XML文件设置背景 我们还可以使用XML文件来设置视图的背景。以下是一个XML文件的例子: <?xml version="1.0" encoding="utf-8"?> <shape xmlns:android="http://schemas.android.com/apk/res/android" android:shape="rectangle"> <gradient android:startColor="#77c9d4" android:endColor="#3996ab" android:angle="270" /> </shape> 将上述文件保存为bg.xml,在视图中使用以下代码: view.setBackgroundResource(R.drawable.bg); 在这个例子中,setBackgroundResource()方法在视图中设置了背景图像。 我们可以使用不同的方法来设置视图的背景,根据需要选择一个背景设置方法。 但请注意:在开发移动应用程序时,设置合适的背景会对应用程序的用户界面有很大影响。因此,在设置背景之前,请确认其符合您的应用场景与目标受众。 ### 回答3: setBackground()是Android View类的一个方法,可以将一个视图的背景设置为指定的Drawable对象。它可以接受各种类型的Drawable对象,例如BitmapDrawable、ColorDrawable、GradientDrawable等等。该方法必须在UI线程中被调用,因为它会更新UI,如果在非UI线程中使用,就会抛出异常。 示例代码: ``` ImageView imageView = findViewById(R.id.imageView); Drawable drawable = getResources().getDrawable(R.drawable.background); imageView.setBackground(drawable); ``` 在上面的示例中,我们可以看到如何使用setBackground()方法将ImageView的背景设置为R.drawable.background资源的Drawable对象。 值得注意的是,setBackground()方法会替换视图原来的背景,如果您需要在视图上添加多个背景,可以使用LayerDrawable对象创建多个Drawable层。 在使用setBackground()方法时,我们还可以设置一些其他的属性,例如背景透明度、背景是否裁剪到视图范围等等。可以通过View类的其他方法来实现这些属性的设置。 总之,setBackground()是一个非常实用的方法,能够让我们轻松地设置视图的背景,提升应用程序的用户体验。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值