在relativelayout中改变imageview的位置

时间:2016-07-20 07:33:46

标签: android imageview position

我正在使用比赛和加入游戏。我喜欢以下 enter image description here

如果我通过匹配完美来完成关卡然后所有图像视图和按钮都被禁用但当我打开图像视图的相同页面位置时保持相同。我想在播放一次后改变图像视图运行时间的位置。< / p>

enter image description here

随机更改右侧图像视图的位置。我没有尝试任何相关的东西。只是尝试找到解决方案并搜索了很多但找不到解决方案。

谢谢 我的XML就像这样

<?xml version="1.0" encoding="utf-8"?>
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:ads="http://schemas.android.com/apk/lib/com.google.ads"
   android:id="@+id/frameLayoutAlpha2"
   android:layout_width="match_parent"
   android:layout_height="match_parent"
   android:orientation="vertical" >

<RelativeLayout
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:gravity="center" >

    <Button
        android:id="@+id/btn1Alpha2"
        style="@style/itemText"
        android:layout_alignParentLeft="true"
        android:layout_gravity="left"
        android:background="@drawable/changebgclick"
        android:text="Ff"
        android:textAllCaps="false" />

    <Button
        android:id="@+id/btn2Alpha2"
        style="@style/itemText"
        android:layout_alignParentLeft="true"
        android:layout_below="@+id/btn1Alpha2"
        android:layout_gravity="left"
        android:background="@drawable/changebgclick"
        android:text="Gg"
        android:textAllCaps="false" />

    <Button
        android:id="@+id/btn3Alpha2"
        style="@style/itemText"
        android:layout_alignParentLeft="true"
        android:layout_below="@+id/btn2Alpha2"
        android:layout_gravity="left"
        android:background="@drawable/changebgclick"
        android:text="Hh"
        android:textAllCaps="false" />

    <Button
        android:id="@+id/btn4Alpha2"
        style="@style/itemText"
        android:layout_alignParentLeft="true"
        android:layout_below="@+id/btn3Alpha2"
        android:layout_gravity="left"
        android:background="@drawable/changebgclick"
        android:text="Ii"
        android:textAllCaps="false" />

    <Button
        android:id="@+id/btn5Alpha2"
        style="@style/itemText"
        android:layout_alignParentLeft="true"
        android:layout_below="@+id/btn4Alpha2"
        android:layout_gravity="left"
        android:background="@drawable/changebgclick"
        android:text="Jj"
        android:textAllCaps="false" />



    <ImageButton
        android:id="@+id/btn2_itemAlpha2"
        style="@style/itemStyle"
        android:layout_alignParentRight="true"
        android:layout_below="@+id/btn1_itemAlpha2"
        android:layout_gravity="right"
        android:background="@drawable/changebgclick"
        android:src="@drawable/i_1" />

    <ImageButton
        android:id="@+id/btn3_itemAlpha2"
        style="@style/itemStyle"
        android:layout_alignParentRight="true"
        android:layout_below="@+id/btn2_itemAlpha2"
        android:layout_gravity="right"
        android:background="@drawable/changebgclick"
        android:src="@drawable/f_2" />

    <ImageButton
        android:id="@+id/btn4_itemAlpha2"
        style="@style/itemStyle"
        android:layout_alignParentRight="true"
        android:layout_below="@+id/btn3_itemAlpha2"
        android:layout_gravity="right"
        android:background="@drawable/changebgclick"
        android:src="@drawable/j_2" />

     <ImageButton
        android:id="@+id/btn1_itemAlpha2"
        style="@style/itemStyle"
        android:layout_alignParentRight="true"
        android:layout_gravity="right"
        android:background="@drawable/changebgclick"
        android:src="@drawable/g_2" />
    <ImageButton
        android:id="@+id/btn5_itemAlpha2"
        style="@style/itemStyle"
        android:layout_alignParentRight="true"
        android:layout_below="@+id/btn4_itemAlpha2"
        android:layout_gravity="right"
        android:background="@drawable/changebgclick"
        android:src="@drawable/h_2" />
</RelativeLayout>

我这样匹配和加入..

    Boolean firstclickedAlpha2, firstPairAlpha2, secondClickedAlpha2,
        secondPairAlpha2, ThirdclickedAlpha2, thirdPairAlpha2,
        ForthclickedAlpha2, ForthPairAlpha2, FifthclickedAlpha2,
        FifthPairAlpha2;
    Button btn1Alpha2, btn2Alpha2, btn3Alpha2, btn4Alpha2, btn5Alpha2;
    ImageButton btn1_itemAlpha2, btn2_itemAlpha2, btn3_itemAlpha2,
        btn4_itemAlpha2, btn5_itemAlpha2;
    FrameLayout frameLayoutAlpha2;
    String FLAGALPHA2;
    View lastView;

    @Override
    public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState, R.layout.activity_alphabate_second);

    bindView();
    init();
    addListener();

}

private void init() {
    firstclickedAlpha2 = true;
    firstPairAlpha2 = true;
    secondClickedAlpha2 = true;
    secondPairAlpha2 = true;
    ThirdclickedAlpha2 = true;
    thirdPairAlpha2 = true;
    ForthclickedAlpha2 = true;
    ForthPairAlpha2 = true;
    FifthclickedAlpha2 = true;
    FifthPairAlpha2 = true;
    FLAGALPHA2 = "Alpha2";

    isHome = false;
    selectDrawerItem(1);
    setHeaderTitle("Match Alphabate");
}

private void bindView() {
    btn1Alpha2 = (Button) findViewById(R.id.btn1Alpha2);
    btn2Alpha2 = (Button) findViewById(R.id.btn2Alpha2);
    btn3Alpha2 = (Button) findViewById(R.id.btn3Alpha2);
    btn4Alpha2 = (Button) findViewById(R.id.btn4Alpha2);
    btn5Alpha2 = (Button) findViewById(R.id.btn5Alpha2);
    frameLayoutAlpha2 = (FrameLayout) findViewById(R.id.frameLayoutAlpha2);
    btn1_itemAlpha2 = (ImageButton) findViewById(R.id.btn1_itemAlpha2);
    btn2_itemAlpha2 = (ImageButton) findViewById(R.id.btn2_itemAlpha2);
    btn3_itemAlpha2 = (ImageButton) findViewById(R.id.btn3_itemAlpha2);
    btn4_itemAlpha2 = (ImageButton) findViewById(R.id.btn4_itemAlpha2);
    btn5_itemAlpha2 = (ImageButton) findViewById(R.id.btn5_itemAlpha2);
}

private void addListener() {
    btn1Alpha2.setOnClickListener(new OnClickListener() {

        @Override
        public void onClick(View arg0) {
            firstclickedAlpha2 = false;
            if (!firstclickedAlpha2 && !firstPairAlpha2) {
                btn1Alpha2.setBackgroundResource(R.drawable.green_bg);
                btn3_itemAlpha2.setBackgroundResource(R.drawable.green_bg);
                btn1Alpha2.setClickable(false);
                btn3_itemAlpha2.setClickable(false);

                Utils.collapse(btn1Alpha2, btn3_itemAlpha2,
                        frameLayoutAlpha2, getApplicationContext());
                Utils.getStatus(btn1Alpha2, btn2Alpha2, btn3Alpha2,
                        btn4Alpha2, btn5Alpha2, AlphabateSecond.this,
                        FLAGALPHA2);

            } else {

                secondPairAlpha2 = true;
                thirdPairAlpha2 = true;
                ForthPairAlpha2 = true;
                FifthPairAlpha2 = true;
                secondClickedAlpha2 = true;
                ThirdclickedAlpha2 = true;
                ForthclickedAlpha2 = true;
                FifthclickedAlpha2 = true;
            }
        }
    });

    btn3_itemAlpha2.setOnClickListener(new OnClickListener() {

        @Override
        public void onClick(View arg0) {
            firstPairAlpha2 = false;
            if (!firstclickedAlpha2 && !firstPairAlpha2) {
                btn3_itemAlpha2.setBackgroundResource(R.drawable.green_bg);
                btn1Alpha2.setBackgroundResource(R.drawable.green_bg);
                btn1Alpha2.setClickable(false);
                btn3_itemAlpha2.setClickable(false);

                Utils.collapse(btn1Alpha2, btn3_itemAlpha2,
                        frameLayoutAlpha2, getApplicationContext());
                Utils.getStatus(btn1Alpha2, btn2Alpha2, btn3Alpha2,
                        btn4Alpha2, btn5Alpha2, AlphabateSecond.this,
                        FLAGALPHA2);

            } else {
                secondPairAlpha2 = true;
                thirdPairAlpha2 = true;
                ForthPairAlpha2 = true;
                FifthPairAlpha2 = true;
                secondClickedAlpha2 = true;
                ThirdclickedAlpha2 = true;
                ForthclickedAlpha2 = true;
                FifthclickedAlpha2 = true;
            }
        }
    });

    btn2Alpha2.setOnClickListener(new OnClickListener() {

        @Override
        public void onClick(View arg0) {
            secondClickedAlpha2 = false;
            if (!secondClickedAlpha2 && !secondPairAlpha2) {
                btn2Alpha2.setBackgroundResource(R.drawable.green_bg);
                btn1_itemAlpha2.setBackgroundResource(R.drawable.green_bg);
                btn2Alpha2.setClickable(false);
                btn1_itemAlpha2.setClickable(false);

                Utils.collapse(btn2Alpha2, btn1_itemAlpha2,
                        frameLayoutAlpha2, getApplicationContext());
                Utils.getStatus(btn1Alpha2, btn2Alpha2, btn3Alpha2,
                        btn4Alpha2, btn5Alpha2, AlphabateSecond.this,
                        FLAGALPHA2);

                firstPairAlpha2 = true;
                thirdPairAlpha2 = true;
                ForthPairAlpha2 = true;
                FifthPairAlpha2 = true;
                firstclickedAlpha2 = true;
                ThirdclickedAlpha2 = true;
                ForthclickedAlpha2 = true;
                FifthclickedAlpha2 = true;
            }
        }
    });

    btn1_itemAlpha2.setOnClickListener(new OnClickListener() {

        @Override
        public void onClick(View arg0) {
            secondPairAlpha2 = false;
            if (!secondClickedAlpha2 && !secondPairAlpha2) {
                btn2Alpha2.setBackgroundResource(R.drawable.green_bg);
                btn1_itemAlpha2.setBackgroundResource(R.drawable.green_bg);
                btn2Alpha2.setClickable(false);
                btn1_itemAlpha2.setClickable(false);

                Utils.collapse(btn2Alpha2, btn1_itemAlpha2,
                        frameLayoutAlpha2, getApplicationContext());
                Utils.getStatus(btn1Alpha2, btn2Alpha2, btn3Alpha2,
                        btn4Alpha2, btn5Alpha2, AlphabateSecond.this,
                        FLAGALPHA2);

            } else {

                firstPairAlpha2 = true;
                thirdPairAlpha2 = true;
                ForthPairAlpha2 = true;
                FifthPairAlpha2 = true;
                firstclickedAlpha2 = true;
                ThirdclickedAlpha2 = true;
                ForthclickedAlpha2 = true;
                FifthclickedAlpha2 = true;
            }
        }
    });

    btn3Alpha2.setOnClickListener(new OnClickListener() {

        @Override
        public void onClick(View arg0) {
            ThirdclickedAlpha2 = false;
            if (!ThirdclickedAlpha2 && !thirdPairAlpha2) {
                btn3Alpha2.setBackgroundResource(R.drawable.green_bg);
                btn5_itemAlpha2.setBackgroundResource(R.drawable.green_bg);
                btn3Alpha2.setClickable(false);
                btn5_itemAlpha2.setClickable(false);

                Utils.collapse(btn3Alpha2, btn5_itemAlpha2,
                        frameLayoutAlpha2, getApplicationContext());
                Utils.getStatus(btn1Alpha2, btn2Alpha2, btn3Alpha2,
                        btn4Alpha2, btn5Alpha2, AlphabateSecond.this,
                        FLAGALPHA2);

            } else {

                firstPairAlpha2 = true;
                secondPairAlpha2 = true;
                ForthPairAlpha2 = true;
                FifthPairAlpha2 = true;
                firstclickedAlpha2 = true;
                secondClickedAlpha2 = true;
                ForthclickedAlpha2 = true;
                FifthclickedAlpha2 = true;
            }
        }
    });

    btn5_itemAlpha2.setOnClickListener(new OnClickListener() {

        @Override
        public void onClick(View arg0) {
            thirdPairAlpha2 = false;
            if (!ThirdclickedAlpha2 && !thirdPairAlpha2) {
                btn3Alpha2.setBackgroundResource(R.drawable.green_bg);
                btn5_itemAlpha2.setBackgroundResource(R.drawable.green_bg);
                btn3Alpha2.setClickable(false);
                btn5_itemAlpha2.setClickable(false);

                Utils.collapse(btn3Alpha2, btn5_itemAlpha2,
                        frameLayoutAlpha2, getApplicationContext());
                Utils.getStatus(btn1Alpha2, btn2Alpha2, btn3Alpha2,
                        btn4Alpha2, btn5Alpha2, AlphabateSecond.this,
                        FLAGALPHA2);

            } else {

                firstPairAlpha2 = true;
                secondPairAlpha2 = true;
                ForthPairAlpha2 = true;
                FifthPairAlpha2 = true;
                firstclickedAlpha2 = true;
                secondClickedAlpha2 = true;
                ForthclickedAlpha2 = true;
                FifthclickedAlpha2 = true;
            }
        }
    });

    btn4Alpha2.setOnClickListener(new OnClickListener() {

        @Override
        public void onClick(View arg0) {
            ForthclickedAlpha2 = false;
            if (!ForthclickedAlpha2 && !ForthPairAlpha2) {
                btn4Alpha2.setBackgroundResource(R.drawable.green_bg);
                btn2_itemAlpha2.setBackgroundResource(R.drawable.green_bg);
                btn4Alpha2.setClickable(false);
                btn2_itemAlpha2.setClickable(false);

                Utils.collapse(btn4Alpha2, btn2_itemAlpha2,
                        frameLayoutAlpha2, getApplicationContext());
                Utils.getStatus(btn1Alpha2, btn2Alpha2, btn3Alpha2,
                        btn4Alpha2, btn5Alpha2, AlphabateSecond.this,
                        FLAGALPHA2);

            } else {

                firstPairAlpha2 = true;
                secondPairAlpha2 = true;
                ForthPairAlpha2 = true;
                thirdPairAlpha2 = true;
                firstclickedAlpha2 = true;
                secondClickedAlpha2 = true;
                ThirdclickedAlpha2 = true;
                FifthclickedAlpha2 = true;
            }
        }
    });

    btn2_itemAlpha2.setOnClickListener(new OnClickListener() {

        @Override
        public void onClick(View arg0) {
            ForthPairAlpha2 = false;
            if (!ForthclickedAlpha2 && !ForthPairAlpha2) {
                btn4Alpha2.setBackgroundResource(R.drawable.green_bg);
                btn2_itemAlpha2.setBackgroundResource(R.drawable.green_bg);
                btn4Alpha2.setClickable(false);
                btn2_itemAlpha2.setClickable(false);

                Utils.collapse(btn4Alpha2, btn2_itemAlpha2,
                        frameLayoutAlpha2, getApplicationContext());
                Utils.getStatus(btn1Alpha2, btn2Alpha2, btn3Alpha2,
                        btn4Alpha2, btn5Alpha2, AlphabateSecond.this,
                        FLAGALPHA2);

            } else {

                firstPairAlpha2 = true;
                secondPairAlpha2 = true;
                ForthPairAlpha2 = true;
                thirdPairAlpha2 = true;
                firstclickedAlpha2 = true;
                secondClickedAlpha2 = true;
                ThirdclickedAlpha2 = true;
                FifthclickedAlpha2 = true;
            }
        }
    });

    btn5Alpha2.setOnClickListener(new OnClickListener() {

        @Override
        public void onClick(View arg0) {
            FifthclickedAlpha2 = false;
            if (!FifthclickedAlpha2 && !FifthPairAlpha2) {
                btn5Alpha2.setBackgroundResource(R.drawable.green_bg);
                btn4_itemAlpha2.setBackgroundResource(R.drawable.green_bg);
                btn5Alpha2.setClickable(false);
                btn4_itemAlpha2.setClickable(false);

                Utils.collapse(btn5Alpha2, btn4_itemAlpha2,
                        frameLayoutAlpha2, getApplicationContext());
                Utils.getStatus(btn1Alpha2, btn2Alpha2, btn3Alpha2,
                        btn4Alpha2, btn5Alpha2, AlphabateSecond.this,
                        FLAGALPHA2);

            } else {

                firstPairAlpha2 = true;
                secondPairAlpha2 = true;
                ForthPairAlpha2 = true;
                thirdPairAlpha2 = true;
                firstclickedAlpha2 = true;
                secondClickedAlpha2 = true;
                ThirdclickedAlpha2 = true;
                FifthclickedAlpha2 = true;
            }
        }
    });

    btn4_itemAlpha2.setOnClickListener(new OnClickListener() {

        @Override
        public void onClick(View arg0) {
            FifthPairAlpha2 = false;
            if (!FifthclickedAlpha2 && !FifthPairAlpha2) {
                btn5Alpha2.setBackgroundResource(R.drawable.green_bg);
                btn4_itemAlpha2.setBackgroundResource(R.drawable.green_bg);
                btn5Alpha2.setClickable(false);
                btn4_itemAlpha2.setClickable(false);

                Utils.collapse(btn5Alpha2, btn4_itemAlpha2,
                        frameLayoutAlpha2, getApplicationContext());
                Utils.getStatus(btn1Alpha2, btn2Alpha2, btn3Alpha2,
                        btn4Alpha2, btn5Alpha2, AlphabateSecond.this,
                        FLAGALPHA2);

            } else {

                firstPairAlpha2 = true;
                secondPairAlpha2 = true;
                ForthPairAlpha2 = true;
                thirdPairAlpha2 = true;
                firstclickedAlpha2 = true;
                secondClickedAlpha2 = true;
                ThirdclickedAlpha2 = true;
                FifthclickedAlpha2 = true;
            }
        }
    });

}

@Override
public void onClick(View v) {
    if (v == lastView) {
        return;
    }
    switch (v.getId()) {
    case R.id.btn1Alpha2:
    case R.id.btn3_itemAlpha2:
        if (lastView == btn1Alpha2 || lastView == btn3_itemAlpha2) {
            Utils.collapse(btn1Alpha2, btn3_itemAlpha2, frameLayoutAlpha2,
                    this);
        }

        break;
    case R.id.btn2Alpha2:
    case R.id.btn1_itemAlpha2:
        if (lastView == btn2Alpha2 || lastView == btn1_itemAlpha2) {
            Utils.collapse(btn2Alpha2, btn1_itemAlpha2, frameLayoutAlpha2,
                    this);

        }
        break;
    case R.id.btn3Alpha2:
    case R.id.btn5_itemAlpha2:
        if (lastView == btn3Alpha2 || lastView == btn5_itemAlpha2) {
            Utils.collapse(btn3Alpha2, btn5_itemAlpha2, frameLayoutAlpha2,
                    this);

        }
        break;
    case R.id.btn4Alpha2:
    case R.id.btn2_itemAlpha2:
        if (lastView == btn4Alpha2 || lastView == btn2_itemAlpha2) {
            Utils.collapse(btn4Alpha2, btn2_itemAlpha2, frameLayoutAlpha2,
                    this);

        }
        break;
    case R.id.btn5Alpha2:
    case R.id.btn4_itemAlpha2:
        if (lastView == btn5Alpha2 || lastView == btn4_itemAlpha2) {
            Utils.collapse(btn5Alpha2, btn4_itemAlpha2, frameLayoutAlpha2,
                    this);

        }
        break;

    default:
        break;
    }
    lastView = v;

}

0 个答案:

没有答案