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

Android程序開(kāi)發(fā)之使用Design包實(shí)現(xiàn)QQ動(dòng)畫(huà)側(cè)滑效果和滑動(dòng)菜單導(dǎo)航

 更新時(shí)間:2016年07月21日 10:07:25   作者:南塵  
這篇文章主要介紹了Android程序開(kāi)發(fā)之使用Design包實(shí)現(xiàn)QQ動(dòng)畫(huà)側(cè)滑效果和滑動(dòng)菜單導(dǎo)航的相關(guān)資料,非常不錯(cuò),具有參考借鑒價(jià)值,需要的朋友可以參考下

Google在2015的IO大會(huì)上,給我們帶來(lái)了更加詳細(xì)的Material Design設(shè)計(jì)規(guī)范,同時(shí),也給我們帶來(lái)了全新的Android Design Support Library,在這個(gè)support庫(kù)里面,Google給我們提供了更加規(guī)范的MD設(shè)計(jì)風(fēng)格的控件。最重要的是,Android Design Support Library的兼容性更廣,直接可以向下兼容到Android 2.2。這不得不說(shuō)是一個(gè)良心之作。

使用方法很簡(jiǎn)單,只需要添加一句依賴

compile 'com.android.support:design:24.0.0'

先用TabLayout和SnackBar以及Navigation實(shí)現(xiàn)QQ側(cè)滑動(dòng)畫(huà)效果和滑動(dòng)

項(xiàng)目已經(jīng)同步至:https://github.com/nanchen2251/designNavigation-and-tabLayout

上個(gè)整體效果圖

首先帶來(lái)的是TabLayout

Tab滑動(dòng)切換View并不是一個(gè)新的概念,但是Google卻是第一次在support庫(kù)中提供了完整的支持,
而且,Design library的TabLayout 既實(shí)現(xiàn)了固定的選項(xiàng)卡 - view的寬度平均分配,
也實(shí)現(xiàn)了可滾動(dòng)的選項(xiàng)卡 - view寬度不固定同時(shí)可以橫向滾動(dòng)。選項(xiàng)卡可以在程序中動(dòng)態(tài)添加,
但大部分時(shí)間我們都不會(huì)這樣用,通?;瑒?dòng)布局都會(huì)和ViewPager配合起來(lái)使用,所以,我們需要ViewPager來(lái)幫忙:
通過(guò)一句話setupWithViewPager,我們就把ViewPager和TabLayout結(jié)合了起來(lái)。

上個(gè)運(yùn)行圖:

看代碼

首先是主頁(yè)面的XML文件

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
tools:context="com.example.nanchen.designtablayoutdemo.MainActivity">
<android.support.design.widget.TabLayout
android:layout_width="match_parent"
app:tabBackground="@color/colorPrimaryDark"
app:tabTextColor="@android:color/white"
app:tabSelectedTextColor="#04b4ae"
android:layout_height="wrap_content"
android:id="@+id/main_tab_layout"/>
<android.support.v4.view.ViewPager
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1"
android:id="@+id/main_vp"/>
</LinearLayout>

  其中由于必須TabLayout控件是Design包下的,所以必須加上

xmlns:app="http://schemas.android.com/apk/res-auto"<br><br>這樣才可以使用自定義它的屬性。它的屬性有很多,這樣簡(jiǎn)單使用幾個(gè),更多的大家可以去嘗試。<br>這里,我只滾動(dòng)了三個(gè),若是你的APP tab標(biāo)簽多的話,

app:tabMode="scrollable" 必須指定這個(gè)屬性,不然你會(huì)發(fā)現(xiàn)看不到,如果標(biāo)簽數(shù)少,還是建議設(shè)置為固定的,那樣才會(huì)等分。

<br><br>其次是Fragment的XML文件<br><br>

<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context="com.example.nanchen.designtablayoutdemo.BlankFragment">
<!-- TODO: Update blank fragment layout -->
<TextView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:textSize="30sp"
android:gravity="center"
android:id="@+id/fg_text"
android:text="@string/hello_blank_fragment"/>
</FrameLayout>

MainActivity.java

package com.example.nanchen.designtablayoutdemo;
import android.os.Bundle;
import android.support.design.widget.TabLayout;
import android.support.v4.view.ViewPager;
import android.support.v7.app.AppCompatActivity;
import java.util.ArrayList;
import java.util.List;
public class MainActivity extends AppCompatActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
ViewPager vp = (ViewPager) findViewById(R.id.main_vp);
TabLayout tabLayout = (TabLayout) findViewById(R.id.main_tab_layout);
List<String> list = new ArrayList<>();
for (int i = 1; i < 4; i++) {
// list.add(String.format(Locale.CHINA,"第02d%頁(yè)",i));
list.add("第"+i+"頁(yè)");
}
vp.setAdapter(new MyAdapter(getSupportFragmentManager(),list));
tabLayout.setupWithViewPager(vp);
}
}

  FragmenT用于存放下面的數(shù)據(jù)

package com.example.nanchen.designtablayoutdemo;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v4.app.Fragment;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;
/**
* A simple {@link Fragment} subclass.
*/
public class BlankFragment extends Fragment {
public BlankFragment() {
// Required empty public constructor
}
public static BlankFragment newInstance(String text) {
Bundle args = new Bundle();
args.putString("text",text);
BlankFragment fragment = new BlankFragment();
fragment.setArguments(args);
return fragment;
}
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
// Inflate the layout for this fragment
return inflater.inflate(R.layout.fragment_blank, container, false);
}
@Override
public void onViewCreated(View view, @Nullable Bundle savedInstanceState) {
super.onViewCreated(view, savedInstanceState);
TextView text = (TextView) view.findViewById(R.id.fg_text);
String str = getArguments().getString("text");
text.setText(str);
}
}

需要一個(gè)PagerAdapter

自定義一個(gè)。

package com.example.nanchen.designtablayoutdemo;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentManager;
import android.support.v4.app.FragmentPagerAdapter;
import java.util.List;
/**
* Created by 南塵 on 2016/7/12.
*/
public class MyAdapter extends FragmentPagerAdapter {
private List<String> list;
public MyAdapter(FragmentManager fm, List<String> list) {
super(fm);
this.list = list;
}
@Override
public Fragment getItem(int position) {
return BlankFragment.newInstance(list.get(position));
}
@Override
public int getCount() {
return list.size();
}
@Override
public CharSequence getPageTitle(int position) {
return list.get(position);
}
} 

2)再來(lái)看看如何使用Navigation和DrawerLayout實(shí)現(xiàn)側(cè)滑功能的動(dòng)畫(huà)演示

前面講解了Design包下的TabLayout的使用,下面將帶來(lái)NavagationView和DrawLayout以及toolbar的聯(lián)動(dòng)。

NavigationView 通過(guò)提供抽屜導(dǎo)航所需的框架讓實(shí)現(xiàn)更簡(jiǎn)單,同時(shí)它還能夠直接通過(guò)菜單資源文件直接生成導(dǎo)航元素。把NavigationView作為DrawerLayout的內(nèi)容視圖來(lái)使用。NavigationView處理好了和狀態(tài)欄的關(guān)系,可以確保NavigationView在API21+設(shè)備上正確的和狀態(tài)欄交互。

以下代碼在前面代碼的基礎(chǔ)上修改。

MainActivity.java

package com.example.nanchen.designtablayoutdemo;
import android.os.Bundle;
import android.support.design.widget.NavigationView;
import android.support.design.widget.TabLayout;
import android.support.v4.view.GravityCompat;
import android.support.v4.view.ViewPager;
import android.support.v4.widget.DrawerLayout;
import android.support.v7.app.ActionBarDrawerToggle;
import android.support.v7.app.AppCompatActivity;
import android.support.v7.widget.Toolbar;
import android.view.MenuItem;
import android.widget.Toast;
import java.util.ArrayList;
import java.util.List;
public class MainActivity extends AppCompatActivity implements NavigationView.OnNavigationItemSelectedListener {
private DrawerLayout drawerLayout;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
ViewPager vp = (ViewPager) findViewById(R.id.main_vp);
TabLayout tabLayout = (TabLayout) findViewById(R.id.main_tab_layout);
Toolbar toolbar = (Toolbar) findViewById(R.id.main_toolbar);
drawerLayout = (DrawerLayout) findViewById(R.id.main_drawerlayout);
//設(shè)置Toolbar和DrawerLayout實(shí)現(xiàn)動(dòng)畫(huà)和聯(lián)動(dòng)
this.setSupportActionBar(toolbar);
ActionBarDrawerToggle toggle = new ActionBarDrawerToggle(this,drawerLayout,toolbar,0,0);
drawerLayout.addDrawerListener(toggle);//設(shè)置監(jiān)聽(tīng)
toggle.syncState();//加上同步
getSupportActionBar().setDefaultDisplayHomeAsUpEnabled(true);
List<String> list = new ArrayList<>();
for (int i = 1; i < 5; i++) {
// list.add(String.format(Locale.CHINA,"第02d%頁(yè)",i));
list.add("第"+i+"頁(yè)");
}
vp.setAdapter(new MyAdapter(getSupportFragmentManager(),list));
tabLayout.setupWithViewPager(vp);
NavigationView navigationView = (NavigationView) findViewById(R.id.main_navigation);
navigationView.setNavigationItemSelectedListener(this);
}
@Override
public boolean onNavigationItemSelected(MenuItem item) {
switch (item.getItemId()) {
case R.id.menu_item1:
Toast.makeText(this,"你點(diǎn)擊了菜單1",Toast.LENGTH_SHORT).show();
break;
case R.id.menu_item2:
Toast.makeText(this,"你點(diǎn)擊了菜單2",Toast.LENGTH_SHORT).show();
break;
case R.id.menu_item3:
Toast.makeText(this,"你點(diǎn)擊了菜單3",Toast.LENGTH_SHORT).show();
break;
case R.id.menu_item4:
Toast.makeText(this,"你點(diǎn)擊了菜單4",Toast.LENGTH_SHORT).show();
break;
}
drawerLayout.closeDrawer(GravityCompat.START);
return true;
}
}

主布局

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
tools:context="com.example.nanchen.designtablayoutdemo.MainActivity">
<!--Toolbar,ActionBar的替代品-->
<android.support.v7.widget.Toolbar
android:id="@+id/main_toolbar"
app:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar"
android:background="@color/colorPrimary"
android:layout_width="match_parent"
android:layout_height="?actionBarSize"/>
<android.support.v4.widget.DrawerLayout
android:layout_width="match_parent"
android:layout_height="0dp"
android:id="@+id/main_drawerlayout"
android:layout_weight="1">
<LinearLayout
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent">
<android.support.design.widget.TabLayout
android:layout_width="match_parent"
app:tabBackground="@color/colorPrimaryDark"
app:tabTextColor="@android:color/white"
app:tabSelectedTextColor="#04b4ae"
android:layout_height="wrap_content"
android:id="@+id/main_tab_layout"/>
<android.support.v4.view.ViewPager
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1"
android:id="@+id/main_vp"/>
</LinearLayout>
<android.support.design.widget.NavigationView
app:menu="@menu/navigation"
android:id="@+id/main_navigation"
android:layout_gravity="start"
app:headerLayout="@layout/header"
app:itemIconTint="@color/navigation_selector"
app:itemTextColor="@color/navigation_selector"
android:layout_width="match_parent"
android:layout_height="match_parent">
</android.support.design.widget.NavigationView>
</android.support.v4.widget.DrawerLayout>
</LinearLayout> 

 navigation.xml

<?xml version="1.0" encoding="utf-8"?>
<menu xmlns:android="http://schemas.android.com/apk/res/android">
<group android:checkableBehavior="single">
<item android:id="@+id/single_1" android:title="單選1" android:icon="@mipmap/ic_launcher"/>
<item android:id="@+id/single_2" android:title="單選2" android:icon="@mipmap/ic_launcher"/>
<item android:id="@+id/single_3" android:title="單選3" android:icon="@mipmap/ic_launcher"/>
</group>
<item android:id="@+id/menu_item1" android:title="菜單1" android:icon="@mipmap/ic_launcher"/>
<item android:id="@+id/menu_item2" android:title="菜單2" android:icon="@mipmap/ic_launcher"/>
<item android:id="@+id/menu_item3" android:title="菜單3" android:icon="@mipmap/ic_launcher"/>
<item android:id="@+id/menu_item4" android:title="菜單4" android:icon="@mipmap/ic_launcher"/>
</menu>  

header.xml

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:orientation="vertical"
android:gravity="center"
android:background="@drawable/header_bg"
android:layout_height="200dp">
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@mipmap/ic_launcher"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="文本"/>
</LinearLayout>

header.bg.xml

<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android">
<gradient android:type="linear" android:angle="45"
android:startColor="#143e52" android:endColor="#06a0ff"/>
</shape>

navigation_selector.xml

<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:color="#fa08ca" android:state_checked="true"/>
<item android:color="#6b6a6a" android:state_checked="false"/>
</selector> 

以上所述是小編給大家介紹的Android程序開(kāi)發(fā)之使用Design包實(shí)現(xiàn)QQ動(dòng)畫(huà)側(cè)滑效果和滑動(dòng)菜單導(dǎo)航,希望對(duì)大家有所幫助,如果大家有任何疑問(wèn)請(qǐng)給我留言,小編會(huì)及時(shí)回復(fù)大家的。在此也非常感謝大家對(duì)腳本之家網(wǎng)站的支持!

相關(guān)文章

  • Android實(shí)現(xiàn)網(wǎng)易云音樂(lè)高仿版流程

    Android實(shí)現(xiàn)網(wǎng)易云音樂(lè)高仿版流程

    這篇文章主要介紹了Android實(shí)現(xiàn)網(wǎng)易云音樂(lè)高仿版,包含了首頁(yè)復(fù)雜發(fā)現(xiàn)界面布局和功能,文中示例代碼介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下
    2022-08-08
  • android 網(wǎng)絡(luò)連接處理分析

    android 網(wǎng)絡(luò)連接處理分析

    在Android中,可以有多種方式來(lái)實(shí)現(xiàn)網(wǎng)絡(luò)編程,本文將詳細(xì)介紹android 網(wǎng)絡(luò)連接處理,需要了解的朋友可以參考下
    2012-11-11
  • 輕松實(shí)現(xiàn)安卓(Android)九宮格解鎖

    輕松實(shí)現(xiàn)安卓(Android)九宮格解鎖

    在平常使用手機(jī)的過(guò)程中,九宮格解鎖是我們經(jīng)常接觸到的。常見(jiàn)的比如有鎖屏中的九宮格,還有支付寶中的九宮格等。因?yàn)榫艑m格可以保護(hù)用戶的隱私,所以它的應(yīng)用面很廣泛。那么今天我們就來(lái)自定義一個(gè)屬于自己的九宮格吧!
    2016-08-08
  • Android中設(shè)置RadioButton在文字右邊的方法實(shí)例

    Android中設(shè)置RadioButton在文字右邊的方法實(shí)例

    這篇文章主要介紹了Android中設(shè)置RadioButton在文字右邊的方法實(shí)例,本文直接給出XML配置實(shí)現(xiàn)代碼,需要的朋友可以參考下
    2015-04-04
  • Android高仿微信表情輸入與鍵盤(pán)輸入詳解

    Android高仿微信表情輸入與鍵盤(pán)輸入詳解

    本文主要介紹 Android高仿微信表情輸入與鍵盤(pán),這里提供了詳細(xì)的相關(guān)資料及實(shí)現(xiàn)示例代碼,有興趣的小伙伴可以參考下
    2016-08-08
  • Android開(kāi)發(fā)教程之獲取系統(tǒng)輸入法高度的正確姿勢(shì)

    Android開(kāi)發(fā)教程之獲取系統(tǒng)輸入法高度的正確姿勢(shì)

    這篇文章主要給大家介紹了關(guān)于Android開(kāi)發(fā)教程之獲取系統(tǒng)輸入法高度的正確姿勢(shì),文中通過(guò)示例代碼介紹的非常詳細(xì),對(duì)大家學(xué)習(xí)或者使用Android具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來(lái)一起學(xué)習(xí)學(xué)習(xí)吧
    2018-10-10
  • Android Activity的4種啟動(dòng)模式圖文介紹

    Android Activity的4種啟動(dòng)模式圖文介紹

    這篇文章主要給大家介紹了關(guān)于Android Activity的4種啟動(dòng)模式,文中通過(guò)示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來(lái)一起學(xué)習(xí)學(xué)習(xí)吧
    2020-11-11
  • Android Studio出現(xiàn)Failed to pull selection: open failed: Permission denied的解決思路

    Android Studio出現(xiàn)Failed to pull selection: open failed: Permi

    本篇文章給大家分享了Android Studio中導(dǎo)出數(shù)據(jù)庫(kù)文件的方法以及出現(xiàn)Failed to pull selection: open failed: Permission denied的解決思路,有興趣的學(xué)習(xí)下。
    2018-05-05
  • RecyclerView仿應(yīng)用列表實(shí)現(xiàn)網(wǎng)格布局

    RecyclerView仿應(yīng)用列表實(shí)現(xiàn)網(wǎng)格布局

    這篇文章主要為大家詳細(xì)介紹了RecyclerView仿應(yīng)用列表實(shí)現(xiàn)網(wǎng)格布局,具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下
    2019-09-09
  • Android自定義view之太極圖的實(shí)現(xiàn)教程

    Android自定義view之太極圖的實(shí)現(xiàn)教程

    這篇文章主要給大家介紹了關(guān)于Android自定義view之太極圖的相關(guān)資料,文中通過(guò)示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來(lái)一起學(xué)習(xí)學(xué)習(xí)吧
    2021-01-01

最新評(píng)論