728x90
728x170
1. MainActivity.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39 |
package ...
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.view.MotionEvent;
import android.view.View;
import android.widget.EditText;
import android.widget.FrameLayout;
public class MainActivity extends AppCompatActivity {
EditText editText;
EditText editText2;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
editText = (EditText) findViewById(R.id.editText);
editText2 = (EditText) findViewById(R.id.editText2);
FrameLayout layout1 = (FrameLayout) findViewById(R.id.layout1);
layout1.setOnTouchListener(new View.OnTouchListener() {
@Override
public boolean onTouch(View v, MotionEvent event) {
float x = event.getX();
float y = event.getY();
editText.setText(String.valueOf(x));
editText2.setText(String.valueOf(y));
return true;
}
});
}
}
|
cs |
2. activity_main.xml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66 |
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context="org.androidtown.javaandandroidchap7.MainActivity">
<TextView
android:id="@+id/textView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="X 좌표"
android:textSize="30dp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintTop_toTopOf="parent" />
<EditText
android:id="@+id/editText"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:ems="10"
android:inputType="textPersonName"
android:layout_alignParentTop="true"
android:layout_alignParentRight="true"
android:layout_alignParentEnd="true"
android:layout_toRightOf="@+id/textView"
android:layout_toEndOf="@+id/textView" />
<TextView
android:id="@+id/textView2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:layout_below="@+id/editText"
android:text="Y 좌표"
android:textSize="30dp" />
<EditText
android:id="@+id/editText2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:ems="10"
android:inputType="textPersonName"
android:layout_below="@+id/editText"
android:layout_alignLeft="@+id/editText"
android:layout_alignStart="@+id/editText"
android:layout_alignParentRight="true"
android:layout_alignParentEnd="true" />
<FrameLayout
android:id="@+id/layout1"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_below="@+id/editText2"
android:background="#00ff00"
android:layout_alignParentBottom="true">
</FrameLayout>
</RelativeLayout>
|
cs |
3. Result
728x90
그리드형(광고전용)
'Source Code > Android' 카테고리의 다른 글
리스트뷰 (ListView) 사용 예시 3 (0) | 2017.05.09 |
---|---|
리스트뷰 (ListView) 사용 예시 2 (0) | 2017.05.09 |
리스트뷰 (ListView) 사용 예시 1 (0) | 2017.05.09 |
프레임 레이아웃을 이용한 버튼 클릭 시 그림 전환 (0) | 2017.05.09 |
스택 (Stack) & 큐 (Queue) (0) | 2017.05.07 |
버튼을 누를 때 마다 스크롤뷰에 담겨진 레이아웃에 텍스트뷰 넣는 방법 (0) | 2017.05.06 |