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

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

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

項目實現(xiàn):(實現(xiàn)Android Studio 基本有兩種實現(xiàn)方式:一種為.MainActivity跳轉(zhuǎn);第二種是Relatelayout布局跳轉(zhuǎn)。

這里著重介紹第一種:(首先需要建立兩個XML文件,進行布局的相互的跳轉(zhuǎn),然后使用兩個JAVA進行相關(guān)的的設(shè)計?。?/strong>

(左上角四個文件為此次建立的新文件夾)

首先設(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>  

另一個頁面布局的設(shè)計: 

代碼設(shè)計:

<?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="這是第二個頁面!"
        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>

然后是第一個JAVA代碼的設(shè)計:

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);
 
        //按鈕進行監(jiān)聽
        button.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                //監(jiān)聽按鈕,如果點擊,就跳轉(zhuǎn)
                Intent intent = new Intent();
                //前一個(MainActivity.this)是目前頁面,后面一個是要跳轉(zhuǎn)的下一個頁面
                intent.setClass(MainActivity.this,Sencond.class);
                startActivity(intent);
            }
        });
    }
}
 

另一個跳轉(zhuǎn)文件所需要的頁面JAVA代碼:

public class Sencond extends AppCompatActivity { 
        @Override  
        protected void onCreate(Bundle savedInstanceState) {  
            super.onCreate(savedInstanceState);  
            //這個是獲取布局文件的,這里是你下一個頁面的布局文件//注意這個是跳轉(zhuǎn)界面的不能設(shè)置錯,應(yīng)該是第一個  
                setContentView(R.layout.sencond);  
        }  
    }  

最后一點著重說明一下項目實現(xiàn)的遇到的問題:

1.沒有注冊相關(guān)的文件名稱: 

2.新建XML文件的時候的字符設(shè)計出現(xiàn)大寫錯誤(設(shè)置XML文件的時候注意了,別設(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.遇到的第三個小問題(出現(xiàn)導(dǎo)入圖片文件錯位,主要設(shè)置背景圖片需要將圖片復(fù)制到相關(guān)的xhdpi文件當(dāng)中) 

最終效果:

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

總結(jié)

到此這篇關(guān)于Android Studio實現(xiàn)簡單頁面跳轉(zhuǎn)的文章就介紹到這了,更多相關(guān)Android Studio頁面跳轉(zhuǎn)內(nèi)容請搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持腳本之家!

相關(guān)文章

  • Android中ScrollView實現(xiàn)滑動距離監(jiān)聽器的方法

    Android中ScrollView實現(xiàn)滑動距離監(jiān)聽器的方法

    ScrollView相信對每位Android開發(fā)者們來說都不陌生,所以這篇文章給大家主要介紹了Android中ScrollView實現(xiàn)滑動距離監(jiān)聽器的方法,有需要的朋友們可以參考借鑒,下面來一起看看吧。
    2016-10-10
  • Android實現(xiàn)收到新短信后自動發(fā)郵件功能

    Android實現(xiàn)收到新短信后自動發(fā)郵件功能

    這篇文章主要為大家詳細(xì)介紹了Android實現(xiàn)收到新短信后自動發(fā)郵件功能,文中示例代碼介紹的非常詳細(xì),具有一定的參考價值,感興趣的小伙伴們可以參考一下
    2022-05-05
  • Android?Studio實現(xiàn)帶三角函數(shù)對數(shù)運算功能的高級計算器

    Android?Studio實現(xiàn)帶三角函數(shù)對數(shù)運算功能的高級計算器

    這篇文章主要為大家詳細(xì)介紹了Android?Studio實現(xiàn)帶三角函數(shù)對數(shù)運算功能的高級計算器,文中示例代碼介紹的非常詳細(xì),具有一定的參考價值,感興趣的小伙伴們可以參考一下
    2022-05-05
  • Android 微信小視頻錄制功能實現(xiàn)詳細(xì)介紹

    Android 微信小視頻錄制功能實現(xiàn)詳細(xì)介紹

    這篇文章主要介紹了Android 微信小視頻錄制功能實現(xiàn)詳解的相關(guān)資料,這里提供了具體的實現(xiàn)思路及代碼,需要的朋友可以參考下
    2016-11-11
  • Android實現(xiàn)屏幕旋轉(zhuǎn)四個方向準(zhǔn)確監(jiān)聽

    Android實現(xiàn)屏幕旋轉(zhuǎn)四個方向準(zhǔn)確監(jiān)聽

    這篇文章主要為大家詳細(xì)介紹了Android實現(xiàn)屏幕旋轉(zhuǎn)四個方向準(zhǔn)確監(jiān)聽,文中示例代碼介紹的非常詳細(xì),具有一定的參考價值,感興趣的小伙伴們可以參考一下
    2022-07-07
  • 如何利用Kotlin實現(xiàn)極簡回調(diào)

    如何利用Kotlin實現(xiàn)極簡回調(diào)

    這篇文章主要給大家介紹了關(guān)于如何利用Kotlin實現(xiàn)極簡回調(diào)的相關(guān)資料,文中通過示例代碼介紹的非常詳細(xì),對大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧
    2019-01-01
  • Android搜索結(jié)果顯示高亮實例(有數(shù)據(jù)滑動底部自動刷新)

    Android搜索結(jié)果顯示高亮實例(有數(shù)據(jù)滑動底部自動刷新)

    本篇文章主要介紹了Android搜索結(jié)果顯示高亮實例(有數(shù)據(jù)滑動底部自動刷新),非常具有實用價值,需要的朋友可以參考下
    2017-04-04
  • Kotlin四大組件中的broadcast廣播

    Kotlin四大組件中的broadcast廣播

    Android開發(fā)的四大組件分別是:活動(activity),用于表現(xiàn)功能;服務(wù)(service),后臺運行服務(wù),不提供界面呈現(xiàn);廣播接受者(Broadcast Receive),勇于接收廣播;內(nèi)容提供者(Content Provider),支持多個應(yīng)用中存儲和讀取數(shù)據(jù),相當(dāng)于數(shù)據(jù)庫,本篇著重介紹廣播組件
    2022-12-12
  • MaterialApp?Flutter?應(yīng)用全局配置與主題管理詳解

    MaterialApp?Flutter?應(yīng)用全局配置與主題管理詳解

    這篇文章主要為大家介紹了MaterialApp?Flutter?應(yīng)用全局配置與主題管理詳解,有需要的朋友可以借鑒參考下,希望能夠有所幫助,祝大家多多進步,早日升職加薪
    2023-03-03
  • Kotlin之在Gradle中無參(no-arg)編譯器插件的使用詳解

    Kotlin之在Gradle中無參(no-arg)編譯器插件的使用詳解

    這篇文章主要介紹了Kotlin之在Gradle中無參(no-arg)編譯器插件的使用詳解,文中通過示例代碼介紹的非常詳細(xì),對大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧
    2019-11-11

最新評論