仿百度壁纸client(六)——完结篇之Gallery画廊实现壁纸预览已经项目细节优化
仿百度壁纸client(六)——完结篇之Gallery画廊实现壁纸预览已经项目细节优化
百度壁纸系列
仿百度壁纸client(一)——主框架搭建,自己定义Tab + ViewPager + Fragment
仿百度壁纸client(二)——主页自己定义ViewPager广告定时轮播图
仿百度壁纸client(三)——首页单向,双向事件冲突处理,壁纸列表的实现
仿百度壁纸client(四)——自己定义上拉载入实现精选壁纸墙
我们这里有一个细节还没有实现。我们先看一下官方的效果
这个学名叫做Gallery画廊。我们今天也来实现它。我们在精选的Fragment中给GradView设置点击事件,让他跳转到画廊。实际开发其中是获取当前点击的图片的,这里我们就仅仅能模拟图片了
myGridView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
startActivity(new Intent(getActivity(), GalleryActivity.class));
}
});
跳转的Activity就是我们今天来实现的,我们先来下个布局
layout_gallery.xml
<?
xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@drawable/image_home_background">
<Gallery
android:id="@+id/myGallery"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerInParent="true" />
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:gravity="center_horizontal"
android:orientation="vertical">
<LinearLayout
android:layout_width="150dp"
android:layout_height="wrap_content"
android:gravity="center"
android:orientation="horizontal">
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@drawable/image_view_button_set_as_wallpaper" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:gravity="center"
android:text="设置壁纸"
android:textColor="#fff" />
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="50dp"
android:orientation="horizontal">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight="1"
android:gravity="center">
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@drawable/image_view_button_preview" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="预览"
android:textColor="#fff" />
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight="1"
android:gravity="center">
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@drawable/image_view_button_download" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="下載"
android:textColor="#fff" />
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight="1"
android:gravity="center">
<ImageView
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:src="@drawable/image_view_button_share" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="分享"
android:textColor="#fff" />
</LinearLayout>
</LinearLayout>
</LinearLayout>
</RelativeLayout>
然后開始实现了。这个不是什么难的技术,仅仅是一个容器。我们还得定义一个Adapter,这里直接放上代码。毕竟就几行代码
package com.lgl.baiduwallpaper;
import android.app.Activity;
import android.content.Context;
import android.os.Bundle;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.Gallery;
import android.widget.ImageView;
import java.util.ArrayList;
/**
* 画廊效果
* Created by lgl on 16/4/9.
*/
public class GalleryActivity extends Activity {
//画廊
private Gallery mGallery;
private ArrayList<Integer> srcData = new ArrayList<>();
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.layout_gallery);
init();
}
private void init() {
mGallery = (Gallery) findViewById(R.id.myGallery);
initData();
mGallery.setAdapter(new myAdapter(this));
}
/**
* 初始化数据
*/
private void initData() {
//这里模拟四张。实际开发中须要自己去获取
srcData.add(R.mipmap.img1);
srcData.add(R.mipmap.img2);
srcData.add(R.mipmap.img3);
srcData.add(R.mipmap.img4);
}
private class myAdapter extends BaseAdapter {
private Context mContext;
public myAdapter(Context mContext) {
this.mContext = mContext;
}
@Override
public int getCount() {
return srcData.size();
}
@Override
public Object getItem(int position) {
return srcData.get(position);
}
@Override
public long getItemId(int position) {
return position;
}
@Override
public View getView(int position, View convertView, ViewGroup parent) {
ImageView imageView = new ImageView(mContext);
imageView.setBackgroundResource(srcData.get(position));
imageView.setLayoutParams(new Gallery.LayoutParams(Gallery.LayoutParams.MATCH_PARENT, Gallery.LayoutParams.WRAP_CONTENT));
return imageView;
}
}
}
记得在清单文件注冊哦
我们来执行一下
项目细节处理
换上LOGO
这个项目还是得按流畅来一遍。所以,引导页少不了的
IndexActivity
package com.lgl.baiduwallpaper;
import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
/**
* Created by lgl on 16/4/9.
*/
public class IndexActivity extends Activity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_index);
new Thread(new Runnable() {
@Override
public void run() {
try {
Thread.sleep(2000);
startActivity(new Intent(IndexActivity.this, MainActivity.class));
finish();
} catch (InterruptedException e) {
e.printStackTrace();
}
}
}).start();
}
}
相应的布局
activity_index.xml
<?xml version="1.0" encoding="utf-8"?
>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@drawable/welcome_bg">
<TextView
android:id="@+id/tv_title"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:layout_marginTop="30dp"
android:text="百度壁纸"
android:textSize="50dp" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@+id/tv_title"
android:layout_centerHorizontal="true"
android:layout_marginTop="10dp"
android:text="每天换壁纸,天天好心情" />
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:src="@drawable/welcome_bottom" />
</RelativeLayout>
执行结果
接下来。我们把title完好一下,首先是精选
<RelativeLayout
android:id="@+id/rl_title"
android:layout_width="match_parent"
android:layout_height="50dp"
android:alpha="0.8"
android:background="#000">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerInParent="true"
android:text="精选"
android:textColor="#fff"
android:textSize="16sp" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_centerVertical="true"
android:layout_marginRight="10dp"
android:text="刷新"
android:textColor="#fff"
android:textSize="16sp" />
</RelativeLayout>
然後就是搜索了
<RelativeLayout
android:id="@+id/rl_title"
android:layout_width="match_parent"
android:layout_height="50dp"
android:alpha="0.8"
android:background="#000">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerInParent="true"
android:text="搜索"
android:textColor="#fff"
android:textSize="16sp" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_centerVertical="true"
android:layout_marginRight="10dp"
android:text="确定"
android:textColor="#fff"
android:textSize="16sp" />
</RelativeLayout>
<RelativeLayout
android:id="@+id/rl_search"
android:layout_width="match_parent"
android:layout_height="50dp"
android:layout_below="@+id/rl_title"
android:layout_margin="10dp">
<EditText
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@drawable/image_search_button" />
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_centerVertical="true"
android:layout_marginRight="10dp"
android:src="@drawable/image_search_clear_button_selected" />
</RelativeLayout>
接著是本地,本地我们不实现它的功能,就写个布局吧
<?
xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<RelativeLayout
android:id="@+id/rl_title"
android:layout_width="match_parent"
android:layout_height="50dp"
android:alpha="0.8"
android:background="#000">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerInParent="true"
android:text="本地"
android:textColor="#fff"
android:textSize="16sp" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_centerVertical="true"
android:layout_marginRight="10dp"
android:text="删除"
android:textColor="#fff"
android:textSize="16sp" />
</RelativeLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1"
android:gravity="center"
android:orientation="vertical">
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@drawable/image_manage_no_wallpaper_logo" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="你本地还没有壁纸,快来下载些吧!
" />
<Button
android:background="@drawable/button_pressed"
android:layout_width="100dp"
android:layout_height="50dp"
android:layout_marginTop="30dp"
android:text="精选"
android:textColor="#fff" />
</LinearLayout>
</LinearLayout>
最後就是設置了
<?xml version="1.0" encoding="utf-8"?
>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_margin="10dp"
android:orientation="vertical">
<RelativeLayout
android:id="@+id/rl_title"
android:layout_width="match_parent"
android:layout_height="50dp"
android:alpha="0.8"
android:background="#000">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerInParent="true"
android:text="设置"
android:textColor="#fff"
android:textSize="16sp" />
<TextView
android:visibility="gone"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_centerVertical="true"
android:layout_marginRight="10dp"
android:text="确定"
android:textColor="#fff"
android:textSize="16sp" />
</RelativeLayout>
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="50dp"
android:background="@drawable/image_more_subitems_bottom"
android:gravity="center_vertical">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="10dp"
android:text="自己主动更换壁纸" />
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_marginRight="10dp"
android:src="@drawable/image_list_open_item" />
</RelativeLayout>
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="50dp"
android:background="@drawable/image_more_subitems_bottom"
android:gravity="center_vertical">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="10dp"
android:text="一鍵更换壁纸" />
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_marginRight="10dp"
android:src="@drawable/image_list_open_item" />
</RelativeLayout>
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="50dp"
android:background="@drawable/image_more_subitems_bottom"
android:gravity="center_vertical">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="10dp"
android:text="图片浏览之类" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_marginRight="10dp"
android:text="自己主动" />
</RelativeLayout>
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="50dp"
android:background="@drawable/image_more_subitems_bottom"
android:gravity="center_vertical">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="10dp"
android:text="清除缓存" />
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_marginRight="10dp"
android:src="@drawable/image_list_open_item"
android:visibility="invisible" />
</RelativeLayout>
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="50dp"
android:background="@drawable/image_more_subitems_bottom"
android:gravity="center_vertical">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="10dp"
android:text="检查更新" />
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_marginRight="10dp"
android:src="@drawable/image_list_open_item"
android:visibility="invisible" />
</RelativeLayout>
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="50dp"
android:layout_marginTop="30dp"
android:background="@drawable/image_more_subitems_bottom"
android:gravity="center_vertical">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="10dp"
android:text="帮助手冊" />
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_marginRight="10dp"
android:src="@drawable/image_list_open_item" />
</RelativeLayout>
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="50dp"
android:background="@drawable/image_more_subitems_bottom"
android:gravity="center_vertical">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="10dp"
android:text="意见反馈" />
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_marginRight="10dp"
android:src="@drawable/image_list_open_item" />
</RelativeLayout>
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="50dp"
android:background="@drawable/image_more_subitems_bottom"
android:gravity="center_vertical">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="10dp"
android:text="关于我们" />
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_marginRight="10dp"
android:src="@drawable/image_list_open_item" />
</RelativeLayout>
</LinearLayout>
我们完整的预览一遍
感兴趣的能够下载Demo玩玩
Demo下载:http://download.csdn.net/detail/qq_26787115/9485945
仿百度壁纸client(六)——完结篇之Gallery画廊实现壁纸预览已经项目细节优化的更多相关文章
- 仿百度壁纸客户端(六)——完结篇之Gallery画廊实现壁纸预览已经项目细节优化
仿百度壁纸客户端(六)--完结篇之Gallery画廊实现壁纸预览已经项目细节优化 百度壁纸系列 仿百度壁纸客户端(一)--主框架搭建,自定义Tab + ViewPager + Fragment 仿百度 ...
- 对百度WebUploader的二次封装,精简前端代码之图片预览上传(两句代码搞定上传)
前言 本篇文章上一篇: 对百度WebUploader开源上传控件的二次封装,精简前端代码(两句代码搞定上传) 此篇是在上面的基础上扩展出来专门上传图片的控件封装. 首先我们看看效果: 正文 使用方式同 ...
- 仿百度壁纸client(五)——实现搜索动画GestureDetector手势识别,动态更新搜索keyword
仿百度壁纸client(五)--实现搜索动画GestureDetector手势识别,动态更新搜索关键字 百度壁纸系列 仿百度壁纸client(一)--主框架搭建,自己定义Tab + ViewPager ...
- 仿百度壁纸客户端(五)——实现搜索动画GestureDetector手势识别,动态更新搜索关键字
仿百度壁纸客户端(五)--实现搜索动画GestureDetector手势识别,动态更新搜索关键字 百度壁纸系列 仿百度壁纸客户端(一)--主框架搭建,自定义Tab + ViewPager + Frag ...
- 仿百度壁纸客户端(二)——主页自定义ViewPager广告定时轮播图
仿百度壁纸客户端(二)--主页自定义ViewPager广告定时轮播图 百度壁纸系列 仿百度壁纸客户端(一)--主框架搭建,自定义Tab + ViewPager + Fragment 仿百度壁纸客户端( ...
- 仿百度壁纸客户端(一)——主框架搭建,自定义Tab+ViewPager+Fragment
仿百度壁纸客户端(一)--主框架搭建,自定义Tab+ViewPager+Fragment 百度壁纸系列 仿百度壁纸客户端(一)--主框架搭建,自定义Tab + ViewPager + Fragment ...
- Canvas 仿百度贴吧客户端 loading 小球
前言 几天前在简书上看到在一篇文章<Android仿百度贴吧客户端Loading小球>,看了一下作者,他写了两个好玩的 demo,效果图如下: 今天趁着周末有空,用 H5 的 Canvas ...
- WPF仿百度Echarts人口迁移图
GitHub地址:https://github.com/ptddqr/wpf-echarts-map/tree/master 关于大名鼎鼎的百度Echarts我就不多说了 不了解的朋友直接看官方的例子 ...
- ArcGIS JS 学习笔记2 实现仿百度的拖拽画圆
一.前言 吐槽一下,百度在国内除了百度地图是良心产品外,其他的真的不敢恭维.在上一篇笔记里,我已经实现了自定义的地图测量模块.在百度地图里面(其他地图)都有一个周边搜索的功能,拖拽画一个圆,然后以圆半 ...
随机推荐
- c/c++相关面试准备笔记1
在c++程序中调用被C编译器编译后的函数,为什么要加extern “C”? C++语言支持函数重载,C语言不支持函数重载.函数被C++编译后在库中的名字与C语言的不同.C++提供了C连接交换指定符号 ...
- Linux下多进程服务端客户端模型二(粘包问题与一种解决方法)
一.Linux发送网络消息的过程 (1) 应用程序调用write()将消息发送到内核中 ( 2)内核中的缓存达到了固定长度数据后,一般是SO_SNDBUF,将发送到TCP协议层 (3)IP层从TCP层 ...
- 51nod 1873 初中的算术【Java BigDecimal/高精度小数】
1873 初中的算术 基准时间限制:1 秒 空间限制:131072 KB 分值: 10 难度:2级算法题 收藏 关注 Noder现在上初三了,正在开始复习中考.他每天要计算型如 (a× a× a× ...
- flow JavaScript 静态类型检查工具
内置类型 flow 内置类型有 boolean, number, string, null, void, any, mixed, literal type. 其中 boolean, number, s ...
- teamviewer13报错
用自己的笔记本电脑远程桌面AGV电脑在终端运行teamviewer报错如下: Init...CheckCPU: SSE2 support: yesChecking setup...Launching ...
- 【bzoj2190】【仪仗队】欧拉函数+线性筛(浅尝ACM-J)
向大(hei)佬(e)势力学(di)习(tou) Description 作为体育委员,C君负责这次运动会仪仗队的训练.仪仗队是由学生组成的N * N的方阵,为了保证队伍在行进中整齐划一,C君会跟在仪 ...
- iOS UI、Xcode、调试、代码等常见问题总汇(持续更新中)
以前比较懒,遇到问题解决了就完事了,有些问题再次遇到时忘记了当初是怎么解决的,又要查各种资料来解决.好记忆不如烂笔头,不管简单还是复杂都记一下吧,所以决定写一篇常见问题总结,方便以后查阅.现在有点忙, ...
- @selector和SEL
遇到selector发现不是很明白,网上搜到的零零星星的介绍也不成体系,索性自己翻译一下,加深一下印象.原文来自官方API文档下的Selectors. Selectors 在OC中,selector有 ...
- Ubuntu 16.04使用“从互联网自动获取”时间无法写入硬件BIOS的奇怪问题
目前发现的就是这个问题,只能手动同步到BIOS. 如果是手动设置过时间,那么可以正常同步到BIOS. 而如果切换到从互联网自动获取时间时,是不能同步到BIOS的,但是界面上的时间确实最新的. 并且这个 ...
- js常用函数和常用技巧
学习和工作的过程中总结的干货,包括常用函数.常用js技巧.常用正则表达式.git笔记等.为刚接触前端的童鞋们提供一个简单的查询的途径,也以此来缅怀我的前端学习之路. PS:此文档,我会持续更新. Aj ...