ändern Sie hintergrund-Bild von Framelayout über die URL

ist es möglich, eine url zu setzen background für framelayout?

Beispiel:
ich möchte die URL wie diese als meine framelayout hintergrund.

was ich wirklich erreichen möchte, ist, dass, wenn meine Aktivität lädt Sie holt das Bild aus meiner Domäne und verwenden Sie es als mein framelayout hintergrund Bild. ich war in der Lage, dies zu tun, aber ich verwendet eine Bildansicht und eine Schaltfläche.

unten ist der code, den ich verwende:

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();
      }
 }

 }

und hier ist mein XML-codes:

<?xml version="1.0" encoding="utf-8"?>
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="@drawable/rakistaradiobg"
android:orientation="vertical" >

<ImageView
    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" />

<Button
    android:id="@+id/postbutton"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_marginTop="50dp"
    android:text="Button" />

InformationsquelleAutor HeartlessArchangel | 2011-12-21

Schreibe einen Kommentar