所以,我有这个代码:
package com.example.ponto_2d;
import android.app.Activity;
import android.view.Menu;
import android.view.MotionEvent;
import android.widget.TextView;
public class MainActivity extends Activity {
pontos p1=new pontos();
pontos p2=new pontos();
@Override
public boolean onTouchEvent(MotionEvent event) {
TextView tv1 = (TextView) findViewById(R.id.textView2);
int eventaction= event.getAction();
switch (eventaction){
case MotionEvent.ACTION_DOWN:
p1.x=event.getX();
break;
}
tv1.setText(""+p1.x);
return true;
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
getMenuInflater().inflate(R.menu.activity_main, menu);
return true;
}
}
这节课:
package com.example.ponto_2d;
public class pontos {
public double x,y;
public double distancia(pontos p2){
return Math.sqrt((p2.x-x)*(p2.x-x) + (p2.y-y)*(p2.y-y));
}
}
这个 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" >
<TextView
android:id="@+id/textView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:layout_centerHorizontal="true"
android:layout_marginTop="38dp"
android:text="@string/titulo_app"
android:textAppearance="?android:attr/textAppearanceLarge" />
<TextView
android:id="@+id/textView2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_alignParentRight="true"
android:layout_marginBottom="30dp"
android:layout_toRightOf="@+id/textView1"
android:text="@string/valor"
android:textAppearance="?android:attr/textAppearanceSmall" />
<TextView
android:id="@+id/textView3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignBaseline="@+id/textView2"
android:layout_alignBottom="@+id/textView2"
android:layout_alignRight="@+id/textView1"
android:text="@string/distancia_1"
android:textAppearance="?android:attr/textAppearanceMedium" />
</RelativeLayout>
我认为没关系,但是当我运行模拟器时,我什么也得不到,甚至没有一个按钮。关于可能是什么问题的任何想法?