在Android

时间:2015-11-26 13:26:07

标签: android move

我希望每次用户回答正确的问题时图像移动一段距离,我在xml中有相应的布局,但我没有找到任何方法来做这件事。 我的布局中也有一些按钮,我希望它们一直都能修复。

以下是我的xml文件的片段:

<?xml version="1.0" encoding="utf-8"?>
<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:paddingLeft="@dimen/activity_horizontal_margin"
    android:paddingRight="@dimen/activity_horizontal_margin"
    android:paddingTop="@dimen/activity_vertical_margin"
    android:paddingBottom="@dimen/activity_vertical_margin"
    android:gravity="bottom"
    android:background="@drawable/bg"
    tools:context="com.example.lolomahmoud.haqqalshams.bored">



    <Button
        android:layout_width="40dp"
        android:layout_height="40dp"
        android:text="Start"
        android:id="@+id/button"
        android:layout_alignParentBottom="true"
        android:layout_alignParentLeft="true"
        android:layout_alignParentStart="true" />
 <Button
        style="?android:attr/buttonStyleSmall"
        android:layout_width="40dp"
        android:layout_height="40dp"
        android:text="quran"
        android:id="@+id/button3"
        android:layout_alignTop="@+id/button4"
        android:layout_toLeftOf="@+id/button4"
        android:layout_toStartOf="@+id/button4"
        android:onClick="quran"/>

    <Button
        style="?android:attr/buttonStyleSmall"
        android:layout_width="40dp"
        android:layout_height="40dp"

        android:text="char"
        android:id="@+id/button4"

        android:layout_alignTop="@+id/button5"
        android:layout_toLeftOf="@+id/button5"
        android:layout_toStartOf="@+id/button5" />

  </RelativeLayout>

这里是我的java代码:

 protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_bored);tomain = (Button) findViewById(R.id.button);
        mm = (TextView) findViewById(R.id.textView);
        tomain.setOnClickListener(bored.this);
}


------
 protected void onActivityResult(int requestCode, int resultCode, Intent data) {
        // TODO Auto-generated method stub
        super.onActivityResult(requestCode, resultCode, data);
        // check if the request code is same as what is passed  here it is 2
        if (requestCode == 2) {
            // fetch the message String
            String message = data.getStringExtra("MESSAGE");
            // Set the message string in textView
            mm.setText("Your Score is :" + score);
            if (message.equals("true")) {
                rectangle++;//for all true ans}
//here I want the movmet of the button 
}}

0 个答案:

没有答案