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
71
72
73
74
75
76
77
78
79
80
81
82
83
84
activity_main.xml源代码:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical"
    android:background="@drawable/main_img1"
    xmlns:android="http://schemas.android.com/apk/res/android">
 
    <TextView
        android:id="@+id/tv_one"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:ellipsize="marquee"
        android:focusable="true"
        android:focusableInTouchMode="true"
        android:gravity="center"
        android:marqueeRepeatLimit="marquee_forever"
        android:shadowColor="@color/teal_200"
        android:shadowDx="10.0"
        android:shadowDy="10.0"
        android:shadowRadius="3.0"
        android:singleLine="true"
        android:text="@string/main1_tv_one"
        android:textColor="@color/purple_200"
        android:textSize="20sp"
        android:textStyle="bold">
 
        <requestFocus />
    </TextView>
 
 
 
    <LinearLayout
        android:layout_marginTop="200dp"
        android:layout_width="wrap_content"
        android:layout_height="match_parent"
        android:layout_gravity="center">
 
        <Button
            android:id="@+id/main_btn"
            android:layout_width="150dp"
            android:layout_height="75dp"
            android:layout_gravity="center"
            android:background="@drawable/login"></Button>
    </LinearLayout>
 
 
</LinearLayout>
  
MainActivity源代码:
  
package com.example.trafficapp;
 
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
 
import androidx.annotation.Nullable;
import androidx.appcompat.app.AppCompatActivity;
 
 
 
public class MainActivity extends AppCompatActivity implements View.OnClickListener{
 
    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);//找到layout文件夹下的activity_main.xml文件
        findViewById(R.id.main_btn).setOnClickListener(this);//找到这个按钮
    }
 
    @Override
    public void onClick(View view) {
        if(view.getId() == R.id.main_btn){
            //创建一个意图对象,准备跳到指定的活动页面
            Intent intent = new Intent( this,MainActivity2.class);
            //栈中存在待跳转的活动实例时,则重新创建该活动的实例,并清除原实例上方的所有实例
            intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);//设置启动标志
            startActivity(intent);//跳转到意图对象指定的活动页面
        }
    }
}
  
本页面涉及到的内容较少,主要包含了<TextView>的应用,以及对<LinearLayout>线性布局的理解,然后还有通过按钮跳转页面的方法。

  

posted @   a啊嗨hai  阅读(387)  评论(0编辑  收藏  举报
相关博文:
阅读排行:
· 震惊!C++程序真的从main开始吗?99%的程序员都答错了
· 别再用vector<bool>了!Google高级工程师:这可能是STL最大的设计失误
· 单元测试从入门到精通
· 【硬核科普】Trae如何「偷看」你的代码?零基础破解AI编程运行原理
· 上周热点回顾(3.3-3.9)
点击右上角即可分享
微信分享提示