2016-05-03 3 views
-1

Ich möchte ein Bild im Hintergrund auf Android Studio hinzufügen, aber ich habe keine Ahnung, wie es geht. In dem Code unten habe ich öffentliche statische endgültige Farbe BACKGROUND_COLOR = Color.WHITE ;, aber ich möchte es ändern, wenn der Hintergrund ein Bild, keine Farbe ist. Wie mache ich das? DankBackgrand image java

package com.udacity.gamedev.icicles; 

import com.badlogic.gdx.graphics.Color; 
import com.badlogic.gdx.math.Vector2; 


public class Constants { 
    public static final float WORLD_SIZE = 10.0f; 
    public static final Color BACKGROUND_COLOR = Color.WHITE; 


    public static final float PLAYER_HEAD_RADIUS = 0.5f; 
    public static final float PLAYER_HEAD_HEIGHT = 4.0f * PLAYER_HEAD_RADIUS; 
    public static final float PLAYER_LIMB_WIDTH = 0.1f; 
    public static final int PLAYER_HEAD_SEGMENTS = 20; 
    public static final Color PLAYER_COLOR = Color.BLACK; 
    public static final float PLAYER_MOVEMENT_SPEED = 10.0f; 

    public static final float ACCELEROMETER_SENSITIVITY = 0.5f; 
    public static final float GRAVITATIONAL_ACCELERATION = 9.8f; 

    public static final float ICICLES_HEIGHT = 1.0f; 
    public static final float ICICLES_WIDTH = 0.5f; 
    public static final Vector2 ICICLES_ACCELERATION = new Vector2(0, -5.0f); 
    public static final Color ICICLE_COLOR = Color.WHITE; 

    public static final float HUD_FONT_REFERENCE_SCREEN_SIZE = 480.0f; 
    public static final float HUD_MARGIN = 20.0f; 

    public static final String ASY_LABEL = "Hillary"; 
    public static final String EDIUM_LABEL = "Sanders"; 
    public static final String ARD_LABEL = "Next"; 
    public static final String ONE_LABEL = "Carson"; 
    public static final String EASY_LABEL = "Ted"; 
    public static final String MEDIUM_LABEL = "Rubio"; 
    public static final String HARD_LABEL = "Trump"; 
    public static final String SAM_LABEL = "Next"; 

    public static final float ASY_SPAWNS_PER_SECOND = 10; 
    public static final float EDIUM_SPAWNS_PER_SECOND = 15; 
    public static final float ARD_SPAWNS_PER_SECOND = 20; 
    public static final float ONE_SPAWNS_PER_SECOND = 5; 
    public static final float EASY_SPAWNS_PER_SECOND = 10; 
    public static final float MEDIUM_SPAWNS_PER_SECOND = 15; 
    public static final float HARD_SPAWNS_PER_SECOND = 20; 
    public static final float SAM_SPAWNS_PER_SECOND = 25; 

    // TODO: Add constants for the color of each difficulty select circle 
    public static final Color ASY_COLOR = new Color(0xff0000ff); 
    public static final Color EDIUM_COLOR = new Color(0xff0000ff); 
    public static final Color ARD_COLOR = new Color(0, 0, 0, 1); 
    public static final Color ONE_COLOR = new Color(0, 0, 1, 1); 
    public static final Color EASY_COLOR = new Color(0, 0, 1, 1); 
    public static final Color MEDIUM_COLOR = new Color(0, 0, 1, 1); 
    public static final Color HARD_COLOR = new Color(0, 0, 1, 1); 
    public static final Color SAM_COLOR = new Color(0, 0, 0, 1); 

    // TODO: Add constant for the size of the difficulty world 
    public static final float DIFFICULTY_WORLD_SIZE = 780.0f; 

    // TODO: Add constant for the radius of the difficulty select "buttons" 
    public static final float DIFFICULTY_BUBBLE_RADIUS = DIFFICULTY_WORLD_SIZE/12; 

    // TODO: Add constant for the scale of the difficulty labels (1.5 works well) 
    public static final float DIFFICULTY_LABEL_SCALE = 1.5f; 

    // TODO: Add Vector2 constants for the centers of the difficulty select buttons 
    public static final Vector2 ASY_CENTER = new Vector2(DIFFICULTY_WORLD_SIZE/2, DIFFICULTY_WORLD_SIZE/2); 
    public static final Vector2 EDIUM_CENTER = new Vector2(DIFFICULTY_WORLD_SIZE/3, DIFFICULTY_WORLD_SIZE/2); 
    public static final Vector2 ARD_CENTER = new Vector2(DIFFICULTY_WORLD_SIZE/6, DIFFICULTY_WORLD_SIZE/2); 
    public static final Vector2 ONE_CENTER = new Vector2(DIFFICULTY_WORLD_SIZE* 2/3, DIFFICULTY_WORLD_SIZE/2); 
    public static final Vector2 EASY_CENTER = new Vector2(DIFFICULTY_WORLD_SIZE/2, DIFFICULTY_WORLD_SIZE/2); 
    public static final Vector2 MEDIUM_CENTER = new Vector2(DIFFICULTY_WORLD_SIZE/3, DIFFICULTY_WORLD_SIZE/2); 
    public static final Vector2 HARD_CENTER = new Vector2(DIFFICULTY_WORLD_SIZE * 2/3, DIFFICULTY_WORLD_SIZE/2); 
    public static final Vector2 SAM_CENTER = new Vector2(DIFFICULTY_WORLD_SIZE/6, DIFFICULTY_WORLD_SIZE/2); 


    public enum Difficulty { 
     ASY(ASY_SPAWNS_PER_SECOND, ASY_LABEL), 
     EDIUM(EDIUM_SPAWNS_PER_SECOND, EDIUM_LABEL), 
     ARD(ARD_SPAWNS_PER_SECOND, ARD_LABEL), 
     ONE(ONE_SPAWNS_PER_SECOND, ONE_LABEL), 
     EASY(EASY_SPAWNS_PER_SECOND, EASY_LABEL), 
     MEDIUM(MEDIUM_SPAWNS_PER_SECOND, MEDIUM_LABEL), 
     HARD(HARD_SPAWNS_PER_SECOND, HARD_LABEL), 
     SAM(SAM_SPAWNS_PER_SECOND, SAM_LABEL); 

     float spawnRate; 
     String label; 

     Difficulty(float spawnRate, String label) { 
      this.spawnRate = spawnRate; 
      this.label = label; 
     } 
    } 
} 

Antwort

0

Im Allgemeinen, wenn Sie ein konstantes Bild auf einem Hintergrund Layout verwenden anwenden möchten, können Sie das Bild in den ziehbar Ordner in Ihrem Projekt kopieren und etwas tun, wie folgt aus:

Drawable ziehbar = ContextCompat. getDrawable (MainActivity.this, R.drawable.storm); screenLayout.setBackground (Zeichen);

0

Fügen Sie einfach die folgende Zeile in Ihr XML-Layout ein.

android:background="@drawable/background" 

Fügen Sie dann Ihr Bild in den Zeichnungsordner ein.