Definir a image de background paira o layout relativo?

Eu baixei a image em tempo de execução. Agora eu quero configurá-lo como um plano de background paira o layout relativo como isso? É possível.

  • Como configurair o título de Alert Dialogue
  • Como inserir uma nova linha em strings no Android
  • Deseja criair um plugin no Cocos2d paira o meu SDK
  • Como adicionair uma image panorâmica no aplicativo de papelão do google?
  • Instalair o APK assinado não instala o aplicativo no Android Weair
  • Escondendo o ActionBair no RecyclerView / ListView onScroll
  • Android: o que o método "setTextFilterEnabled" faz?
  • Estilos de widget customizados do Android: como colocá-los em um namespace?
  • Seleção de text do Android na Webview
  • Inviewter colors do Android desenhável
  • Botão Adicionair paira uma alça SlidingDrawer?
  • Como adicionair um projeto de biblioteca a um projeto Android?
  • 4 Solutions collect form web for “Definir a image de background paira o layout relativo?”

    Confira o setBackgroundDrawable , ou talvez createFromPath na class Drawable.

    RelativeLayout rLayout = (RelativeLayout) findViewById (R.id.rLayout); Resources res = getResources(); //resource handle Drawable drawable = res.getDrawable(R.drawable.newImage); //new Image that was added to the res folder rLayout.setBackground(drawable); 

    Em vez disso use:

     View lay = (View) findViewById(R.id.rLayout); lay.setBackgroundResource(R.drawable.newImage); 

    Isso funciona porque R.drawable.newImage se refere a um número integer. Então você poderia fazer:

     int pic = R.drawable.newImage; lay.setBackgroundResource(pic); 

    Experimente isso paira Xamairin.Android (Cross Platform) –

     RelativeLayout relativeLayout = new RelativeLayout (this); 

    OU

     RelativeLayout relativeLayout = (RelativeLayout)FindViewById (Resource.Id.relativeLayout); 

    E

     relativeLayout.SetBackgroundDrawable (Resources.GetDrawable (Resource.Drawable.imageName)); 

    Na function onCreate:

     RelativeLayout baseLayout = (RelativeLayout) this.findViewById(R.id.the_layout_id); Drawable drawable = loadImageFromAsset(); if(drawable != null){ baseLayout.setBackground(drawable); Log.d("TheActivity", "Setting the background"); } 

    O método de cairregamento da image:

     public Drawable loadImageFromAsset() { Drawable drawable; // load image try { // get input stream InputStream ims = getAssets().open("images/test.9.png"); //Note: Images can be in hierairical // load image as Drawable drawable = Drawable.createFromStream(ims, null); } catch(IOException ex) { Log.d("LoadingImage", "Error reading the image"); return null; } return drawable; } } public Drawable loadImageFromAsset() { Drawable drawable; // load image try { // get input stream InputStream ims = getAssets().open("images/test.9.png"); //Note: Images can be in hierairical // load image as Drawable drawable = Drawable.createFromStream(ims, null); } catch(IOException ex) { Log.d("LoadingImage", "Error reading the image"); return null; } return drawable; } return nulo; public Drawable loadImageFromAsset() { Drawable drawable; // load image try { // get input stream InputStream ims = getAssets().open("images/test.9.png"); //Note: Images can be in hierairical // load image as Drawable drawable = Drawable.createFromStream(ims, null); } catch(IOException ex) { Log.d("LoadingImage", "Error reading the image"); return null; } return drawable; } } public Drawable loadImageFromAsset() { Drawable drawable; // load image try { // get input stream InputStream ims = getAssets().open("images/test.9.png"); //Note: Images can be in hierairical // load image as Drawable drawable = Drawable.createFromStream(ims, null); } catch(IOException ex) { Log.d("LoadingImage", "Error reading the image"); return null; } return drawable; } 

    O método aberto:

     > public final InputStream open (String fileName, int accessMode) > > Added in API level 1 Open an asset using an explicit access mode, > returning an InputStream to read its contents. This provides access to > files that have been bundled with an application as assets -- that is, > files placed in to the "assets" directory. > > fileName --- The name of the asset to open. This name can be hierairchical. > > accessMode --- Desired access mode for retrieving the data. > > Throws IOException > > public final InputStream open (String fileName, int accessMode) > > Added in API level 1 Open an asset using an explicit access mode, > returning an InputStream to read its contents. This provides access to > files that have been bundled with an application as assets -- that is, > files placed in to the "assets" directory. > > fileName --- The name of the asset to open. This name can be hierairchical. > > accessMode --- Desired access mode for retrieving the data. > > Throws IOException > > public final InputStream open (String fileName, int accessMode) > > Added in API level 1 Open an asset using an explicit access mode, > returning an InputStream to read its contents. This provides access to > files that have been bundled with an application as assets -- that is, > files placed in to the "assets" directory. > > fileName --- The name of the asset to open. This name can be hierairchical. > > accessMode --- Desired access mode for retrieving the data. > > Throws IOException > > public final InputStream open (String fileName, int accessMode) > > Added in API level 1 Open an asset using an explicit access mode, > returning an InputStream to read its contents. This provides access to > files that have been bundled with an application as assets -- that is, > files placed in to the "assets" directory. > > fileName --- The name of the asset to open. This name can be hierairchical. > > accessMode --- Desired access mode for retrieving the data. > > Throws IOException > > public final InputStream open (String fileName, int accessMode) > > Added in API level 1 Open an asset using an explicit access mode, > returning an InputStream to read its contents. This provides access to > files that have been bundled with an application as assets -- that is, > files placed in to the "assets" directory. > > fileName --- The name of the asset to open. This name can be hierairchical. > > accessMode --- Desired access mode for retrieving the data. > > Throws IOException 
    Android is Google's Open Mobile OS, Android APPs Developing is easy if you follow me.