最近在玩Esp32,需要APP,順帶學了下這方面的東西。
主要實現功能: 從主 mainActivity 跳轉到otherActivity。
新建一個hello工程,添加 otherActivity 和 otherxml.xml;
mainActivity內容:
package com.example.xiaoyehack.test; import android.support.v7.app.AppCompatActivity; import android.os.Bundle; import android.view.View; import android.content.Intent; public class MainActivity extends AppCompatActivity { @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); } public void skip(View view){ Intent intent = new Intent(); intent.setClass(MainActivity.this,otherActivity.class); startActivity(intent); } }
activity_main.xml
<?xml version="1.0" encoding="utf-8"?> <android.support.constraint.ConstraintLayout 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" tools:context=".MainActivity"> <Button android:id="@+id/button" android:layout_width="wrap_content" android:layout_height="79dp" android:layout_marginStart="148dp" android:layout_marginTop="32dp" android:layout_marginEnd="148dp" android:layout_marginBottom="276dp" android:onClick="skip" android:text="點擊跳轉" app:layout_constraintBottom_toBottomOf="parent" app:layout_constraintEnd_toEndOf="parent" app:layout_constraintStart_toStartOf="parent" app:layout_constraintTop_toBottomOf="@+id/textView3" /> <TextView android:id="@+id/textView3" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_marginStart="122dp" android:layout_marginTop="105dp" android:layout_marginEnd="122dp" android:layout_marginBottom="92dp" android:text="點擊下面按鈕實現跳轉" app:layout_constraintBottom_toTopOf="@+id/button" app:layout_constraintEnd_toEndOf="parent" app:layout_constraintStart_toStartOf="parent" app:layout_constraintTop_toTopOf="parent" /> </android.support.constraint.ConstraintLayout>
otherActivity內容:
package com.example.xiaoyehack.test; import android.os.Bundle; import android.support.v7.app.AppCompatActivity; public class otherActivity extends AppCompatActivity { @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.otherxml); } }
otherxml內容:
<?xml version="1.0" encoding="utf-8"?> <android.support.constraint.ConstraintLayout 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"> <TextView android:id="@+id/textView" android:layout_width="wrap_content" android:layout_height="67dp" android:layout_marginStart="116dp" android:layout_marginTop="146dp" android:layout_marginEnd="100dp" android:layout_marginBottom="346dp" android:text="不要吹牛皮,就是一把梭!" app:layout_constraintBottom_toBottomOf="parent" app:layout_constraintEnd_toEndOf="parent" app:layout_constraintHorizontal_bias="0.0" app:layout_constraintStart_toStartOf="parent" app:layout_constraintTop_toTopOf="parent" app:layout_constraintVertical_bias="0.0" /> </android.support.constraint.ConstraintLayout>
賞幣地址:
https://download.csdn.net/download/qq_18187161/10882442
無幣地址:
鏈接:https://pan.baidu.com/s/1NWPNbkQxMgkGxpNPX9loLw
提取碼:qhnx
提取碼復制可見。