Android?Studio實(shí)現(xiàn)簡(jiǎn)單頁面跳轉(zhuǎn)的詳細(xì)教程
項(xiàng)目實(shí)現(xiàn):(實(shí)現(xiàn)Android Studio 基本有兩種實(shí)現(xiàn)方式:一種為.MainActivity跳轉(zhuǎn);第二種是Relatelayout布局跳轉(zhuǎn)。
這里著重介紹第一種:(首先需要建立兩個(gè)XML文件,進(jìn)行布局的相互的跳轉(zhuǎn),然后使用兩個(gè)JAVA進(jìn)行相關(guān)的的設(shè)計(jì)!)
(左上角四個(gè)文件為此次建立的新文件夾)

首先設(shè)置Activity_main的文件設(shè)置:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background = "@mipmap/bc"
tools:context=".MainActivity">
<TextView
android:id="@+id/one"
android:layout_width="200dp"
android:layout_height="100dp"
android:layout_centerInParent="true"
/>
<Button
android:id="@+id/button"
android:layout_width="299dp"
android:layout_height="63dp"
android:layout_below="@+id/one"
android:layout_centerHorizontal="true"
android:layout_marginTop="87dp"
android:text="你這背景太假了"
tools:ignore="MissingConstraints" />
</RelativeLayout> 另一個(gè)頁面布局的設(shè)計(jì):

代碼設(shè)計(jì):
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background = "@mipmap/ck"
tools:context=".MainActivity">
<TextView
android:id="@+id/two"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="這是第二個(gè)頁面!"
android:textSize="25dp"
android:textColor="#663399"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintTop_toTopOf="parent" />
</LinearLayout>然后是第一個(gè)JAVA代碼的設(shè)計(jì):
public class MainActivity extends AppCompatActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
//獲取按鈕
Button button = (Button) findViewById(R.id.button);
//按鈕進(jìn)行監(jiān)聽
button.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
//監(jiān)聽按鈕,如果點(diǎn)擊,就跳轉(zhuǎn)
Intent intent = new Intent();
//前一個(gè)(MainActivity.this)是目前頁面,后面一個(gè)是要跳轉(zhuǎn)的下一個(gè)頁面
intent.setClass(MainActivity.this,Sencond.class);
startActivity(intent);
}
});
}
}
另一個(gè)跳轉(zhuǎn)文件所需要的頁面JAVA代碼:
public class Sencond extends AppCompatActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
//這個(gè)是獲取布局文件的,這里是你下一個(gè)頁面的布局文件//注意這個(gè)是跳轉(zhuǎn)界面的不能設(shè)置錯(cuò),應(yīng)該是第一個(gè)
setContentView(R.layout.sencond);
}
} 最后一點(diǎn)著重說明一下項(xiàng)目實(shí)現(xiàn)的遇到的問題:
1.沒有注冊(cè)相關(guān)的文件名稱:

2.新建XML文件的時(shí)候的字符設(shè)計(jì)出現(xiàn)大寫錯(cuò)誤(設(shè)置XML文件的時(shí)候注意了,別設(shè)置超過的大寫)
Error:Error: 'O' is not a valid file-based resource name character: File-based resource names must contain only lowercase a-z, 0-9, or underscore Error:Execution failed for task ':bluetooth:mergeDebugResources'. F:\Android_Studio_Project\BLE_APP\bluetooth\src\main\res\layout\automaticOpenLayout.xml: Error: 'O' is not a valid file-based resource name character: File-based resource names must contain only lowercase a-z, 0-9, or underscore F:\Android_Studio_Project\BLE_APP\bluetooth\src\main\res\layout\automaticOpenLayout.xml
3.遇到的第三個(gè)小問題(出現(xiàn)導(dǎo)入圖片文件錯(cuò)位,主要設(shè)置背景圖片需要將圖片復(fù)制到相關(guān)的xhdpi文件當(dāng)中)

最終效果:

跳轉(zhuǎn)后的界面:

總結(jié)
到此這篇關(guān)于Android Studio實(shí)現(xiàn)簡(jiǎn)單頁面跳轉(zhuǎn)的文章就介紹到這了,更多相關(guān)Android Studio頁面跳轉(zhuǎn)內(nèi)容請(qǐng)搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持腳本之家!
相關(guān)文章
Android 自定義view之畫圖板實(shí)現(xiàn)方法
本文重在對(duì)自定義view,以及其常用類,常用方法的初步了解,提供一個(gè)思路,效果是其次,畫板只是例子,需要的朋友可以參考下2018-01-01
Android ConstraintLayout約束布局使用詳解
ConstraintLayout 即約束布局,也是 Android Studio 的默認(rèn)布局,它可以減少布局的層級(jí),改善布局性能。不夸張地說,它基本上可以實(shí)現(xiàn)任何你想要的布局效果,下面,咱們一起來瞧瞧吧2022-11-11
Android開發(fā)筆記之:Splash的實(shí)現(xiàn)詳解
本篇文章是對(duì)Android中Splash的實(shí)現(xiàn)進(jìn)行了詳細(xì)的分析介紹,需要的朋友參考下2013-05-05
Android基礎(chǔ)之startActivityForResult()的用法詳解
這篇文章主要給大家介紹了Android中startActivityForResult()的用法,文中給出了詳細(xì)的介紹與示例代碼,相信對(duì)大家的理解和學(xué)習(xí)具有一定參考借鑒價(jià)值,有需要的朋友們下面來一起看看吧。2017-01-01
Android Studio導(dǎo)入Eclipse項(xiàng)目時(shí).so庫文件的解決方法
這篇文章主要介紹了Android Studio導(dǎo)入Eclipse項(xiàng)目時(shí)項(xiàng)目中".so"庫文件的解決方法,需要的朋友可以參考下2018-06-06
Android 監(jiān)聽屏幕是否鎖屏的實(shí)例代碼
今天小編通過本文給大家分享android如何監(jiān)聽手機(jī)屏幕是否鎖屏。實(shí)現(xiàn)方法很簡(jiǎn)單,需要的朋友參考下吧2017-09-09
Android自定義View圓形和拖動(dòng)圓跟隨手指拖動(dòng)
這篇文章主要介紹了Android自定義View圓形和拖動(dòng)圓跟隨手指拖動(dòng),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下2017-11-11
Android用文件存儲(chǔ)數(shù)據(jù)的方法
這篇文章主要為大家詳細(xì)介紹了Android用文件存儲(chǔ)數(shù)據(jù)的方法,具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下2017-10-10
Android?NDK入門初識(shí)(組件結(jié)構(gòu)開發(fā)流程)
這篇文章主要為大家介紹了Android?NDK入門之初識(shí)組件結(jié)構(gòu)開發(fā)流程詳解,有需要的朋友可以借鑒參考下,希望能夠有所幫助,祝大家多多進(jìn)步,早日升職加薪2023-08-08
分享實(shí)現(xiàn)Android圖片選擇的兩種方式
本文給大家分享的是Android選擇圖片的兩種方式的實(shí)現(xiàn)代碼,分別是單張選取和多張批量選取,非常的實(shí)用,有需要的小伙伴可以參考下2016-01-01

