android设置背景url,android – 通过URL更改Framelayout的背景图片

是否可以使用url为framelayout设置背景?

例:

我想使用像this这样的URL作为我的framelayout背景.

我真正想要实现的是,当我的活动加载时,它将从我的域中获取图像并将其用作我的framelayout背景图像.我能够做到这一点,但我使用了imageview和一个按钮.

下面是我使用的代码:

public class MyAppActivity extends Activity {

ImageView imView;

String imageUrl= "http://www.mydomain.com/resource/images/";

public void onCreate(Bundle savedInstanceState) {

super.onCreate(savedInstanceState);

setContentView(R.layout.main);

Button bt3= (Button)findViewById(R.id.postbutton);

bt3.setOnClickListener(getImgListener);

}

View.OnClickListener getImgListener = new View.OnClickListener()

{

public void onClick(View view) {

downloadFile(imageUrl+"image"+".png");

Log.i("im url",imageUrl+"image"+".png");

}

};

Bitmap bmImg;

void downloadFile(String fileUrl){

URL myFileUrl =null;

try {

myFileUrl= new URL(fileUrl);

} catch (MalformedURLException e) {

// TODO Auto-generated catch block

e.printStackTrace();

}

try {

HttpURLConnection conn= (HttpURLConnection)myFileUrl.openConnection();

conn.setDoInput(true);

conn.connect();

InputStream is = conn.getInputStream();

bmImg = BitmapFactory.decodeStream(is);

imView.setImageBitmap(bmImg);

} catch (IOException e) {

// TODO Auto-generated catch block

e.printStackTrace();

}

}

}

这是我的XML代码:

android:layout_width="fill_parent"

android:layout_height="fill_parent"

android:background="@drawable/rakistaradiobg"

android:orientation="vertical" >

android:id="@+id/imageView1"

android:layout_width="wrap_content"

android:layout_height="98dp"

android:layout_gravity="bottom|center"

android:scaleType="fitXY"

android:src="@drawable/btnbg" />

android:id="@+id/postbutton"

android:layout_width="wrap_content"

android:layout_height="wrap_content"

android:layout_marginTop="50dp"

android:text="Button" />

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值