欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

Android?Studio實(shí)現(xiàn)簡單頁面跳轉(zhuǎn)的詳細(xì)教程

 更新時(shí)間:2023年01月11日 12:10:46   作者:C++_劉斯淇  
這篇文章主要給大家介紹了關(guān)于Android?Studio實(shí)現(xiàn)簡單頁面跳轉(zhuǎn)的詳細(xì)教程,文中通過圖文介紹的非常詳細(xì),對(duì)大家學(xué)習(xí)或者使用Android?Studio具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友可以參考下

項(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ì)?。?/strong>

(左上角四個(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)簡單頁面跳轉(zhuǎn)的文章就介紹到這了,更多相關(guān)Android Studio頁面跳轉(zhuǎn)內(nèi)容請(qǐng)搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持腳本之家!

相關(guān)文章

最新評(píng)論