0

我正在尝试设置 ImageView 的背景,但布局不是活动的 setContentView。

我的布局pieza_j1.xml:

<?xml version="1.0" encoding="utf-8"?>
<ImageView 
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/pieza1"
    android:src="@drawable/osin"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
/>

我的游戏活动。我正在尝试设置背景,但不起作用:

private void setIcon() {
    switch (p1) {
    case 0: 
        View pieza_1 = getLayoutInflater().inflate(R.layout.pieza_j1, null);
        ImageView pieza1 = (ImageView) pieza_1.findViewById(R.id.pieza1);
        pieza1.setImageResource(R.drawable.arribin);

...

游戏活动的布局:

    <?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="#ffffff"
    >

    <LinearLayout 
        android:orientation="vertical"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        android:gravity="center_horizontal"

        >

        <com.sistemasmas.line.views.TopView 
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:id ="@+id/topview"
        />


         <com.sistemasmas.line.views.GameView
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:id ="@+id/gameview"
            android:layout_weight="1"
            android:scaleType="fitXY"

         />  

        <com.sistemasmas.line.views.BottomView 
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:id ="@+id/bottomview"

        />

    </LinearLayout>

</FrameLayout>

还有一个游戏视图:

private int getPieceId(){
    if(board.getPlayersGo()==Players.PLAYER1){


        return R.layout.pieza_j1;
    }
    else{

        return R.layout.pieza_j2;
    }
}

private void addPiece(int i){
    boolean p = powerBall.playNow();
    if(powerPressed){
        p = true;
    }
    MarginLayoutParams mp = new MarginLayoutParams(gameBoard.getPieceDiam(),gameBoard.getPieceDiam());
    if(p){
        newPiece = lInf.inflate(getPowerId(), null);
    }
    else{
        newPiece = lInf.inflate(getPieceId(), null);
    }

...

4

0 回答 0