android开发小程序one

android开发小程序one

要求

有一个界面,里面有组员名字。点击组员名字,调到另一个组员信息界面。

准备

1、android stdio开发工具
2、java语法。
过程

1
2
3
4
5
6
1、创建一个work1项目
2、编辑activity_main.xml(在layout目录下)
3、创建组员.xml(在layout目录下)
4、创建组员acitiviy
5、AndroidManifest中申明acitivy
6、MainActivity中调用

最后目录结构图:

开始

创建work1项目,编辑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
67
68
69
70
<Button
android:id="@+id/zlw"
android:layout_width="102dp"
android:layout_height="45dp"
android:layout_marginBottom="400dp"
android:layout_marginEnd="8dp"
android:layout_marginLeft="8dp"
android:layout_marginRight="8dp"
android:layout_marginStart="8dp"
android:text="张力维"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.458"
app:layout_constraintStart_toStartOf="parent"
tools:ignore="MissingConstraints" />
<Button
android:id="@+id/cyx"
android:layout_width="102dp"
android:layout_height="45dp"
android:layout_marginBottom="350dp"
android:layout_marginEnd="8dp"
android:layout_marginLeft="8dp"
android:layout_marginRight="8dp"
android:layout_marginStart="8dp"
android:text="cyx"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.458"
app:layout_constraintStart_toStartOf="parent"
tools:ignore="MissingConstraints" />
<Button
android:id="@+id/ms"
android:layout_width="102dp"
android:layout_height="45dp"
android:layout_marginBottom="300dp"
android:layout_marginEnd="8dp"
android:layout_marginLeft="8dp"
android:layout_marginRight="8dp"
android:layout_marginStart="8dp"
android:text="ms"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.458"
app:layout_constraintStart_toStartOf="parent"
tools:ignore="MissingConstraints" />
<Button
android:id="@+id/cxw"
android:layout_width="102dp"
android:layout_height="45dp"
android:layout_marginBottom="250dp"
android:layout_marginEnd="8dp"
android:layout_marginLeft="8dp"
android:layout_marginRight="8dp"
android:layout_marginStart="8dp"
android:text="cxw"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.458"
app:layout_constraintStart_toStartOf="parent"
tools:ignore="MissingConstraints" />
<TextView
android:id="@+id/textView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:typeface="monospace"
android:text="@string/introduce" />

创建组员

添加背景图片在res->drawable
bg.jpg,cxw.jpg,cyx.jpg,zlw.jpg
创建组员.xml(layout–>右键–>New–>layout resource file–>cxw)

1
2
3
4
5
6
7
8
9
10
11
12
13
14
<?xml version="1.0" encoding="utf-8"?>
<android.support.constraint.ConstraintLayout
xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@drawable/cxw">
<Button
android:id="@+id/back"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="back"
/>
</android.support.constraint.ConstraintLayout>

创建组员activity,这里继续Activity类

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
package com.zjgsu.work1;
import android.app.Activity;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
//继承 acyiviy
public class cxw extends Activity {
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.cxw); //添加xml
Button back = findViewById(R.id.back);
back.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
/* 消除此activity */
finish();
}
});
}
}

类似创建其三个组员。

声明组员activity

AndroidManifest中申明acitivy

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
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.zjgsu.work1">
<application
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:roundIcon="@mipmap/ic_launcher_round"
android:supportsRtl="true"
android:theme="@style/AppTheme">
<activity android:name=".MainActivity">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<!--申明activity-->
<activity android:name="zlw"></activity>
<activity android:name="ms"></activity>
<activity android:name="cyx"></activity>
<activity android:name="cxw"></activity>
</application>
</manifest>

MainActivity中调用

MainActivity函数

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
package com.zjgsu.work1;
import android.content.Intent;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
public class MainActivity extends AppCompatActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
final Button zlw = (Button) findViewById(R.id.zlw);
final Button cyx = (Button) findViewById(R.id.cyx);
final Button ms = (Button) findViewById(R.id.ms);
final Button cxw = (Button) findViewById(R.id.cxw);
zlw.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
// 切换界面,需要在AndroidManifest.xml中申明activity --zlw
Intent i = new Intent(MainActivity.this , zlw.class);
startActivity(i);
}
});
cyx.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Intent i = new Intent(MainActivity.this , cyx.class);
startActivity(i);
}
});
ms.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Intent i = new Intent(MainActivity.this , ms.class);
startActivity(i);
}
});
cxw.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Intent i = new Intent(MainActivity.this , cxw.class);
startActivity(i);
}
});
}
}

最后附加string.xml

1
2
3
4
<resources>
<string name="app_name">Skr</string>
<string name="introduce">Welcome to Skr team. here are some member\'s information</string>
</resources>

Donate
-------------本文结束感谢您的阅读-------------