android引導頁圖片
㈠ android studio引導頁怎麼做
引導頁的話,一般使用框架就可以了,也可以叫美工製作,然後使用一些視頻播放的技巧。
㈡ android開屏頁的實現--圖片和視屏
圖片引導頁結合咕咚,視屏開屏頁引進螞蜂窩的案例。
一、如何實現android開屏頁,滑動小圓點帶動圖片切換。
大概所有的app都是有這個簡單的需求。第一次進入app時,顯示引導圖再是閃屏圖,之後就只是閃屏咯。實現邏輯就是對是否是第一次進入該app進行判斷,這里可以採取SharedPreferences存儲方式進行記錄下,我們可以寫一個utils用來存儲第一次進入app的狀態。
每次在閃屏界面onCreate()判斷一下。
引導頁的實現--自定一個view
具體實現請查看demo
demo地址
請教一個問題,怎麼在文章里添加動態圖啊?!?!
㈢ android studio怎麼設置引導頁
基本上現在所有的應用都會有一個歡迎界面,在歡迎界面對應用做一個整體的介紹,然後在跳入到主界面,這次要說的這個引導頁就是帶翻頁的引導頁。效果如下所示
概要實現
主要分為兩部分功能,一個是翻頁效果,一個是頁面位置指示器。為了實現翻頁效果我採用系統自帶的ViewPager對象來實現;頁面指示器則通過一個LinearLayout在其中放置相應個數的圖片,然後根據頁面的滑動動態修改各個圖片的資源。布局文件如下所示
復制代碼
1 <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
2 xmlns:tools="http://schemas.android.com/tools"
3 android:layout_width="match_parent"
4 android:layout_height="match_parent"
5 tools:context=".MainActivity" >
6
7 <android.support.v4.view.ViewPager
8 xmlns:android="http://schemas.android.com/apk/res/android"
9 android:id="@+id/welcome_pager"
10 android:layout_width="match_parent"
11 android:layout_height="match_parent" />
12
13 <!-- 圖片位置指示器 -->
14 <LinearLayout
15 android:id="@+id/director"
16 android:layout_width="match_parent"
17 android:layout_height="wrap_content"
18 android:gravity="center_horizontal"
19 android:orientation="horizontal"
20 android:layout_marginBottom="15dip"
21 android:layout_alignParentBottom="true"
22 >
23
24 <ImageView
25 android:layout_width="wrap_content"
26 android:layout_height="wrap_content"
27 android:background="@drawable/pageindicator_on" />
28
29 <ImageView
30 android:layout_width="wrap_content"
31 android:layout_height="wrap_content"
32 android:background="@drawable/pageindicator_off" />
33
34 <ImageView
35 android:layout_width="wrap_content"
36 android:layout_height="wrap_content"
37 android:background="@drawable/pageindicator_off" />
38
39 <ImageView
40 android:layout_width="wrap_content"
41 android:layout_height="wrap_content"
42 android:background="@drawable/pageindicator_off" />
43 </LinearLayout>
44
45 </RelativeLayout>
復制代碼
ViewPager
先來看下官方解釋:Layout manager that allows the user to flip left and right through pages of data.意思是說,Viewpage是一個允許用戶在多個頁面數據之間通過左滑或者右滑的方式切換頁面數據的布局管理器。
主要功能點有兩部分,數據適配器Adapter,和事件監聽器OnPageChangeListener。數據適配器用來管理這個ViewPager對象的顯示內容,而OnPageChangeListener用來處理當頁面切換的時候的行為動作,我修改頁面指示器就是通過這個事件來完成的。
適配器
復制代碼
1 class pagerAdapter extends FragmentPagerAdapter{
2
3 public pagerAdapter(FragmentManager fm) {
4 super(fm);
5 }
6
7 @Override
8 public Fragment getItem(int arg0) {
9 //得到要顯示的對象並初始化圖片
10 WelcomeFragment fm = new WelcomeFragment();
11 fm.setImg(imgs.get(arg0));
12
13 return fm;
14 }
15
16 @Override
17 public int getCount() {
18 return imgs.size();
19 }
20
21 }
復制代碼
上面這段就是ViewPager要用的適配器了,其中imgs是一個id數組,存放了要在歡迎界面展示的圖片的id,WelcomeFragment是一個Fragment類,用來展示頁面內容,這兩個代碼會在完整代碼中體現。兩個方法需要實現,getCout,用來表示有多少個頁面;getItem,用來獲取指定位置的Pager對象。
imgs數組定義及實現:
復制代碼
1 List<Integer> imgs = null;
2 //初始化歡迎界面圖片數組
3 imgs = new ArrayList<Integer>();
4 imgs.add(R.drawable.help1);
5 imgs.add(R.drawable.help2);
6 imgs.add(R.drawable.help3);
7 imgs.add(R.drawable.help4);
復制代碼
WelcomeFragment類定義
復制代碼
1 public class WelcomeFragment extends Fragment {
2
3 View view = null;
4 int imgId ;
5 @Override
6 public View onCreateView(LayoutInflater inflater, ViewGroup container,
7 Bundle savedInstanceState) {
8 view = inflater.inflate(R.layout.welcome_fragment, null);
9
10 ImageView fragmentVw = (ImageView) view.findViewById(R.id.welcome_Img);
11 fragmentVw.setBackgroundResource(imgId);
12 return view;
13 }
14
15 /**
16 * 為該Fragment設置顯示圖片
17 * */
18 public void setImg(int imgID){
19
20 imgId = imgID;
21 }
22 }
復制代碼
WelcomeFragment布局文件
復制代碼
1 <FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
2 android:layout_width="match_parent"
3 android:layout_height="match_parent" >
4
5 <ImageView
6 android:id="@+id/welcome_Img"
7 android:contentDescription="welcome"
8 android:layout_width="match_parent"
9 android:layout_height="match_parent" />
10
11 </FrameLayout>
復制代碼
事件監聽器OnPageChangeListener
這個監聽器用來監聽頁面切換事件,實現這個介面用來處理頁面切換時,頁面指示器跟著改變狀態。實現代碼如下
復制代碼
1 /**
2 * 頁面切換的事件監聽器
3 * */
4 class pageChangeListener implements OnPageChangeListener{
5
6 /**
7 * 當某一個頁面被選中的時候觸發
8 * */
9 @Override
10 public void onPageSelected(int arg0) {
11 int count = directorLayout.getChildCount();
12 /**
13 * 指示器自對象順序和頁面顯示順序一樣的設置為on,其餘的設置為off
14 * */
15 for(int i=0;i<count;i++){
16 ImageView iv = (ImageView) directorLayout.getChildAt(i);
17 if(i == arg0){
18 iv.setBackgroundResource(R.drawable.pageindicator_on);
19 }else{
20 iv.setBackgroundResource(R.drawable.pageindicator_off);
21 }
22 }
23 }
24
25 @Override
26 public void onPageScrolled(int arg0, float arg1, int arg2) {
27 // TODO Auto-generated method stub
28 }
29
30 @Override
31 public void onPageScrollStateChanged(int arg0) {
32 // TODO Auto-generated method stub
33 }
34 }
㈣ android怎麼從引導頁進入主頁
1 import android.app.Activity;
2 import android.content.Intent;
3 import android.content.SharedPreferences;
4 import android.content.SharedPreferences.Editor;
5 import android.os.Bundle;
6 import android.os.Handler;
7
8 /** 歡迎界面 */
9 public class WelcomeAct extends Activity {
10
11 private boolean isFirstIn = false;
12 private static final int TIME = 2000;
13 private static final int GO_HOME = 1000;
14 private static final int GO_GUIDE = 1001;
15
16 private Handler mHandler = new Handler() {
17 public void handleMessage(android.os.Message msg) {
18 switch (msg.what) {
19 // 跳入主界面
20 case GO_HOME:
21 goHome();
22 break;
23 // 跳入引導頁
24 case GO_GUIDE:
25 goGuide();
26 break;
27 }
28 };
29 };
30
31 @Override
32 protected void onCreate(Bundle savedInstanceState) {
33 super.onCreate(savedInstanceState);
34 setContentView(R.layout.welcome);
35 init();
36 }
37
38 private void init() {
39 SharedPreferences perPreferences = getSharedPreferences("jike",
40 MODE_PRIVATE);
41 isFirstIn = perPreferences.getBoolean("isFirstIn", true);
42 if (!isFirstIn) {
43 mHandler.sendEmptyMessageDelayed(GO_HOME, TIME);
44 } else {
45 mHandler.sendEmptyMessageDelayed(GO_GUIDE, TIME);
46 Editor editor = perPreferences.edit();
47 editor.putBoolean("isFirstIn", false);
48 editor.commit();
49 }
50 }
51
52 private void goHome() {
53 Intent i = new Intent(WelcomeAct.this, MainActivity.class);
54 startActivity(i);
55 finish();
56 }
57
58 private void goGuide() {
59 Intent i = new Intent(WelcomeAct.this, Guide.class);
60 startActivity(i);
61 finish();
62 }
63
64 }
1 import java.util.ArrayList;
2 import java.util.List;
3 import android.app.Activity;
4 import android.content.Intent;
5 import android.os.Bundle;
6 import android.support.v4.view.ViewPager;
7 import android.support.v4.view.ViewPager.OnPageChangeListener;
8 import android.view.LayoutInflater;
9 import android.view.View;
10 import android.view.View.OnClickListener;
11 import android.widget.Button;
12 import android.widget.ImageView;
13
14 /** 引導頁 */
15 public class Guide extends Activity implements OnPageChangeListener {
16
17 private ViewPager vp;
18 private ViewPagerAdapter vpAdapter;
19 private List<View> views;
20 private ImageView[] dots;
21 private int[] ids = { R.id.iv1, R.id.iv2, R.id.iv3 };
22 private Button start_btn;
23
24 @Override
25 protected void onCreate(Bundle savedInstanceState) {
26 super.onCreate(savedInstanceState);
27 setContentView(R.layout.guide);
28 initViews();
29 initDots();
30 }
31
32 private void initViews() {
33 LayoutInflater inflater = LayoutInflater.from(this);
34
35 views = new ArrayList<View>();
36 views.add(inflater.inflate(R.layout.one, null));
37 views.add(inflater.inflate(R.layout.two, null));
38 views.add(inflater.inflate(R.layout.three, null));
39
40 vpAdapter = new ViewPagerAdapter(views, this);
41 vp = (ViewPager) findViewById(R.id.viewpager);
42 vp.setAdapter(vpAdapter);
43 // 下標從0開始,所以第三個頁面是get(2)。
44 start_btn = (Button) views.get(2).findViewById(R.id.start_btn);
45 start_btn.setOnClickListener(new OnClickListener() {
46 @Override
47 public void onClick(View arg0) {
48 Intent i = new Intent(Guide.this, MainActivity.class);
49 startActivity(i);
50 finish();
51 }
52 });
53 vp.setOnPageChangeListener(this);
54 }
55
56 /** 循環設置點 */
57 private void initDots() {
58 dots = new ImageView[views.size()];
59 for (int i = 0; i < views.size(); i++) {
60 dots[i] = (ImageView) findViewById(ids[i]);
61 }
62 }
63
64 @Override /** 滑動狀態改變的時候 */
65 public void onPageScrollStateChanged(int arg0) {
66 // TODO Auto-generated method stub
67 }
68
69 @Override /** 當頁面被滑動時候調用 */
70 public void onPageScrolled(int arg0, float arg1, int arg2) {
71 // TODO Auto-generated method stub
72 }
73
74 @Override /** 當前新的頁面被選中時調用 */
75 public void onPageSelected(int arg0) {
76 for (int i = 0; i < ids.length; i++) {
77 if (arg0 == i) {
78 // 亮點
79 dots[i].setImageResource(R.drawable.login_point_selected);
80 } else {
81 // 暗點
82 dots[i].setImageResource(R.drawable.login_point);
83 }
84 }
85 }
86
87 }
1 <?xml version="1.0" encoding="utf-8"?>
2 <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
3 android:layout_width="match_parent"
4 android:layout_height="match_parent" >
5
6 <android.support.v4.view.ViewPager
7 android:id="@+id/viewpager"
8 android:layout_width="fill_parent"
9 android:layout_height="fill_parent"
10 android:background="#00000000" >
11 </android.support.v4.view.ViewPager>
12
13 <!-- 底部三個點 -->
14 <LinearLayout
15 android:id="@+id/ll"
16 android:layout_width="fill_parent"
17 android:layout_height="wrap_content"
18 android:layout_alignParentBottom="true"
19 android:gravity="center_horizontal"
20 android:orientation="horizontal" >
21 <!-- 選中點 -->
22 <ImageView
23 android:id="@+id/iv1"
24 android:layout_width="wrap_content"
25 android:layout_height="wrap_content"
26 android:src="@drawable/login_point_selected" />
27 <!-- 未選中點 -->
28 <ImageView
29 android:id="@+id/iv2"
30 android:layout_width="wrap_content"
31 android:layout_height="wrap_content"
32 android:src="@drawable/login_point" />
33 <!-- 未選中點 -->
34 <ImageView
35 android:id="@+id/iv3"
36 android:layout_width="wrap_content"
37 android:layout_height="wrap_content"
38 android:src="@drawable/login_point" />
39 </LinearLayout>
40
41 </RelativeLayout>
㈤ android 安卓 類似ONE卡片頁(包含圖片文字等)怎麼實現
Android5.0中向我們介紹了一個全新的控制項–CardView,從本質上看,可以將CardView看做是FrameLayout在自身之上添加了圓角和陰影效果。請注意:CardView被包裝為一種布局,並且經常在ListView和RecyclerView的Item布局中,作為一種容器使用。
下面例子來源於android學習手冊, android學習手冊包含9個章節,108個例子,源碼文檔隨便看,例子都是可交互,可運行,源碼採用android studio目錄結構,高亮顯示代碼,文檔都採用文檔結構圖顯示,可以快速定位。360手機助手中下載,排在第四個。
CardView應該被使用在顯示層次性的內容時;在顯示列表或網格時更應該被選擇,因為這些邊緣可以使得用戶更容易去區分這些內容。
使用CardView
首先,假設你的布局如同下面的形式:
<FrameLayout xmlns:app="http://schemas.android.com/apk/res-auto" xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="wrap_content"> <!-- Main Content View --> <RelativeLayout> ... </RelativeLayout> </FrameLayout>
為了使用上面的布局方式來創建一個卡片,首先你需要導入支持的依賴庫(android-support-v7-cardview的jar包)在你的build.gradle文件中。
dependencies { ... compile 'com.android.support:cardview-v7:21.0.2' }
現在將FrameLayout替換為CardView,
<android.support.v7.widget.CardView xmlns:card_view="http://schemas.android.com/apk/res-auto" xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="wrap_content"> <!-- Main Content View --> <RelativeLayout> ... </RelativeLayout> </android.support.v7.widget.CardView>
就是這樣!使用依賴庫能夠保證你的程序穩定的兼容之前的版本;盡管在AndroidL和之前的Android版本中對其處理方式有所不同。