用动作改变3个按钮的位置()

时间:2014-06-15 10:09:51

标签: android

我正在制作我的第一款应用, 当按下按钮(id = button2)按钮的位置会改变时,我需要一种方法,如果你按下按钮1,3,应用程序将退出。 我这样做了:

public void onClick(View v) {

    switch(v.getId()){

    }

    int id = v.getId();
    if (id == R.id.button1) {
        action2();
    } else if (id == R.id.button2) {
        action1();
    } else if (id == R.id.button3) {
        action2();
    }
    }
private void action2() {
    // TODO Auto-generated method stub
    finish();
    System.exit(0);
}
private void action1() {
    // TODO Auto-generated method stub
    changingTextView.setText(+1);
    /* I need here a way to change the buttons places */

}

如何让action1()更改按钮位置? 这是main.xml:

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingBottom="@dimen/activity_vertical_margin"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
tools:context="com.example.bluetap.FirstActivity$PlaceholderFragment" >

<Button
    android:id="@+id/button1"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_alignParentLeft="true"
    android:layout_alignParentTop="true"
    android:minWidth="200dp"
    android:text="Press The White Button"
    android:textColor="@color/blue" />

<Button
    android:id="@+id/button2"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_alignLeft="@+id/button1"
    android:layout_below="@+id/button1"
    android:background="@android:color/white"
    android:minWidth="200dp"
    android:text="Press The White Button"
    android:textColor="@color/blue" />

<Button
    android:id="@+id/button3"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_alignLeft="@+id/button2"
    android:layout_below="@+id/button2"
    android:minWidth="200dp"
    android:text="Press The White Button"
    android:textColor="@color/blue" />

<TextView
    android:id="@+id/changingTextView"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_alignLeft="@+id/button3"
    android:layout_below="@+id/button3"
    android:layout_marginLeft="80dp"
    android:layout_marginTop="95dp"
    android:text="0"
    android:textSize="60sp" />

谢谢你:)

1 个答案:

答案 0 :(得分:0)

这可以帮助您:View.setTranslationX

编辑:也许this thread