最新国产好看的视频,伊人天堂AV在线,国产Aaaaaa视频,蜜臀视频在线观看一区,人妻av色图,密臀久久久精品影片,青青视频免费观看毛片,久草在线观看视,国产三级精品色情在线

基于Viewpager2實現(xiàn)登錄注冊引導(dǎo)頁面

 更新時間:2022年09月05日 15:17:48   作者:_jiaaang  
這篇文章主要為大家詳細(xì)介紹了基于Viewpager2實現(xiàn)登錄注冊引導(dǎo)頁面,文中示例代碼介紹的非常詳細(xì),具有一定的參考價值,感興趣的小伙伴們可以參考一下

本文實例為大家分享了Viewpager2實現(xiàn)登錄注冊引導(dǎo)頁面的具體代碼,供大家參考,具體內(nèi)容如下

介紹

屏幕滑動是兩個完整屏幕之間的切換,在設(shè)置向?qū)Щ蚧脽羝冉缑嬷泻艹R?/p>

實現(xiàn)圖(圖片來源于網(wǎng)絡(luò)):

例子

1、創(chuàng)建視圖

我這里只創(chuàng)建了3個XML

fragment0.xml

<?xml version="1.0" encoding="utf-8"?>
? ? <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
? ? ? ? android:id="@+id/content"
? ? ? ? android:layout_width="match_parent"
? ? ? ? android:layout_height="match_parent" >

? ? <ImageView
? ? ? ? android:layout_width="match_parent"
? ? ? ? android:layout_height="match_parent"
? ? ? ? android:adjustViewBounds="true"
? ? ? ? android:scaleType="fitXY"
? ? ? ? android:src="@drawable/p0"
? ? ? ? />
? ? </LinearLayout>

fragment1.xml

<?xml version="1.0" encoding="utf-8"?>
? ? <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
? ? ? ? android:id="@+id/content"
? ? ? ? android:layout_width="match_parent"
? ? ? ? android:layout_height="match_parent" >

? ? <ImageView
? ? ? ? android:layout_width="match_parent"
? ? ? ? android:layout_height="match_parent"
? ? ? ? android:adjustViewBounds="true"
? ? ? ? android:scaleType="fitXY"
? ? ? ? android:src="@drawable/p1"
? ? ? ? />
? ? </LinearLayout>

fragment2.xml

<?xml version="1.0" encoding="utf-8"?>
? ? <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
? ? ? ? android:id="@+id/content"
? ? ? ? android:layout_width="match_parent"
? ? ? ? android:layout_height="match_parent" >

? ? <ImageView
? ? ? ? android:layout_width="match_parent"
? ? ? ? android:layout_height="match_parent"
? ? ? ? android:adjustViewBounds="true"
? ? ? ? android:scaleType="fitXY"
? ? ? ? android:src="@drawable/p2"
? ? ? ? />
? ? </LinearLayout>

2、創(chuàng)建 Fragment

根據(jù)構(gòu)造方法傳進(jìn)來的 int i;返回不同的視圖(i是等下用到的FragmentStateAdapter適配器中傳進(jìn)去的)

package com.example.xianyu;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.fragment.app.Fragment;


public class mFragment extends Fragment {
? ? int i = 0;
? ? mFragment(int i){

? ? ? ? this.i = i;
? ? }
? ??
? ? @Nullable
? ? @Override
? ? public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
? ? ? ? View view = null;
? ? ? ? switch (i){
? ? ? ? ? ? case 0: {
? ? ? ? ? ? view = inflater.inflate(R.layout.fragment0, container, false);
? ? ? ? ? ? break;
? ? ? ?}
? ? ? ? ? ? case 1: {
? ? ? ? ? ? view = ?inflater.inflate(R.layout.frament1, container, false);
? ? ? ? ? ? break;
? ? ? ? }
? ? ? ? ? ? case 2: {
? ? ? ? ? ? ? ? view = inflater.inflate(R.layout.fragment2, container, false);
? ? ? ? ? ? ? ? break;
? ? ? ? ? ? }
? ? ? ? }
? ? ? ? return view;
? ? }
}

3、主Activity,并創(chuàng)建自定義適配器繼承自FragmentStateAdapter

activity_screen_slide.xml

<?xml version="1.0" encoding="utf-8"?>
<!-- activity_screen_slide.xml -->
<androidx.viewpager2.widget.ViewPager2
? ? xmlns:android="http://schemas.android.com/apk/res/android"
? ? android:id="@+id/pager"
? ? android:layout_width="match_parent"
? ? android:layout_height="match_parent" />

homeActivity

package com.example.xianyu;

import android.os.Bundle;

import androidx.fragment.app.Fragment;
import androidx.fragment.app.FragmentActivity;
import androidx.viewpager2.adapter.FragmentStateAdapter;
import androidx.viewpager2.widget.ViewPager2;

public class homeActivity extends FragmentActivity {
? ? //要顯示的頁數(shù)
? ? private static final int NUM_PAGES = 3;
? ? private ViewPager2 viewPager2;
? ? ?// 適配器,為ViewPager2提供頁面?
? ? private FragmentStateAdapter pagerAdapter;
? ??
? ? @Override
? ? protected void onCreate(Bundle savedInstanceState) {
? ? ? ? super.onCreate(savedInstanceState);
? ? ? ? setContentView(R.layout.activity_screen_slide);
? ? ? ? viewPager2 = findViewById(R.id.pager);
? ? ? ? pagerAdapter = new ScreenSlidePagerAdapter(this);
? ? ? ? viewPager2.setAdapter(pagerAdapter);
? ? }

? ? @Override
? ? public void onBackPressed() {
? ? ? ? if (viewPager2.getCurrentItem() == 0) { ? ? ? ? ? ?
? ? ? ? ? ? super.onBackPressed();
? ? ? ? } else { ? ? ? ? ??
? ? ? ? ? ? viewPager2.setCurrentItem(viewPager2.getCurrentItem() - 1);
? ? ? ? }
? ? }

?//自定義的類,繼承自FragmentStateAdapter適配器
? ? private class ScreenSlidePagerAdapter extends FragmentStateAdapter {
? ? ? ? public ScreenSlidePagerAdapter(FragmentActivity fa) {
? ? ? ? ? ? super(fa);
? ? ? ? }
//主要是createFragment這個方法
? ? ? ? @Override
? ? ? ? public Fragment createFragment(int position) {
? ? ? ? ? ? return new mFragment(position);
? ? ? ? }

? ? ? ? @Override
? ? ? ? public int getItemCount() {
? ? ? ? ? ? return NUM_PAGES;
? ? ? ? }


? ? }
}

以上就是本文的全部內(nèi)容,希望對大家的學(xué)習(xí)有所幫助,也希望大家多多支持腳本之家。

相關(guān)文章

  • 36個Android開發(fā)常用經(jīng)典代碼大全

    36個Android開發(fā)常用經(jīng)典代碼大全

    本篇文章主要介紹了36個Android開發(fā)常用經(jīng)典代碼片段,都是實用的代碼段,具有一定的參考價值,感興趣的小伙伴們可以參考一下。
    2016-11-11
  • Android Studio 透明狀態(tài)欄的實現(xiàn)示例

    Android Studio 透明狀態(tài)欄的實現(xiàn)示例

    這篇文章主要介紹了Android Studio 透明狀態(tài)欄的實現(xiàn)示例,文中通過示例代碼介紹的非常詳細(xì),對大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧
    2021-04-04
  • Android Studio之Debug運行期代碼植入的方法

    Android Studio之Debug運行期代碼植入的方法

    這篇文章主要介紹了Android Studio之Debug運行期代碼植入的方法,小編覺得挺不錯的,現(xiàn)在分享給大家,也給大家做個參考。一起跟隨小編過來看看吧
    2018-07-07
  • Android編程獲取地理位置的經(jīng)度和緯度實例

    Android編程獲取地理位置的經(jīng)度和緯度實例

    這篇文章主要介紹了Android編程獲取地理位置的經(jīng)度和緯度實現(xiàn)方法,結(jié)合實例形式詳細(xì)分析了Android操作系統(tǒng)服務(wù)調(diào)用GPS實現(xiàn)定位的相關(guān)技巧,需要的朋友可以參考下
    2016-01-01
  • Android Jetpack中Room的使用

    Android Jetpack中Room的使用

    這篇文章主要介紹了Android Jetpack中Room的使用,大家都知道Room主要分三個部分 database、dao和實體類entity,本文通過實例代碼給大家介紹的非常詳細(xì),需要的朋友可以參考下
    2021-10-10
  • Kotlin中的contract到底有什么用詳解

    Kotlin中的contract到底有什么用詳解

    Kotlin contracts是一種通知編譯器有關(guān)函數(shù)行為的方式,下面這篇文章主要給大家介紹了關(guān)于Kotlin中contract到底有什么用的相關(guān)資料,文中通過實例代碼介紹的非常詳細(xì),需要的朋友可以參考下
    2022-01-01
  • 搭建Android上的服務(wù)器 “實現(xiàn)隔空取物”的方法

    搭建Android上的服務(wù)器 “實現(xiàn)隔空取物”的方法

    本篇文章主要介紹了搭建Android上的服務(wù)器 “實現(xiàn)隔空取物”的方法,小編覺得挺不錯的,現(xiàn)在分享給大家,也給大家做個參考。一起跟隨小編過來看看吧
    2018-01-01
  • Android Service自啟動注意事項分析

    Android Service自啟動注意事項分析

    這篇文章主要介紹了Android Service自啟動注意事項,結(jié)合實例分析了Android Service自啟動過程中屬性設(shè)置的相關(guān)技巧,需要的朋友可以參考下
    2016-03-03
  • Android實現(xiàn)拍照、錄像、錄音代碼范例

    Android實現(xiàn)拍照、錄像、錄音代碼范例

    這篇文章主要介紹了Android實現(xiàn)拍照、錄像、錄音代碼的相關(guān)資料,具有一定的參考價值,感興趣的小伙伴們可以參考一下。
    2016-10-10
  • Android:Field can be converted to a local varible.的解決辦法

    Android:Field can be converted to a local varible.的解決辦法

    這篇文章主要介紹了Android:Field can be converted to a local varible.的解決辦法的相關(guān)資料,希望通過本文能幫助到大家,讓大家遇到這樣的問題輕松解決,需要的朋友可以參考下
    2017-10-10

最新評論

偃师市| 南岸区| 余干县| 大悟县| 黄陵县| 文成县| 梁平县| 穆棱市| 石狮市| 白玉县| 保德县| 泸定县| 阳春市| 吉木乃县| 怀仁县| 贵阳市| 鄂伦春自治旗| 泗阳县| 台中县| 阜城县| 财经| 泌阳县| 揭阳市| 屯昌县| 英吉沙县| 崇明县| 永定县| 兴和县| 承德县| 新泰市| 通州市| 杭锦后旗| 弥勒县| 天水市| 来宾市| 徐闻县| 晋江市| 张家界市| 隆回县| 丰镇市| 栾川县|