仿百度壁纸客户端(六)——完结篇之Gallery画廊实现壁纸预览已经项目细节优化

简介: <div class="markdown_views"><h1 id="仿百度壁纸客户端六完结篇之gallery画廊实现壁纸预览已经项目细节优化">仿百度壁纸客户端(六)——完结篇之Gallery画廊实现壁纸预览已经项目细节优化</h1><hr><h2 id="百度壁纸系列">百度壁纸系列</h2><blockquote> <p><a href="http://

仿百度壁纸客户端(六)——完结篇之Gallery画廊实现壁纸预览已经项目细节优化


百度壁纸系列

仿百度壁纸客户端(一)——主框架搭建,自定义Tab + ViewPager + Fragment

仿百度壁纸客户端(二)——主页自定义ViewPager广告定时轮播图

仿百度壁纸客户端(三)——首页单向,双向事件冲突处理,壁纸列表的实现

仿百度壁纸客户端(四)——自定义上拉加载实现精选壁纸墙

仿百度壁纸客户端(五)——实现搜索动画GestureDetector手势识别,动态更新搜索关键字

仿百度壁纸客户端(六)——完结篇之Gallery画廊实现壁纸预览已经项目细节优化


我们这里有一个细节还没有实现,我们先看一下官方的效果

这里写图片描述

这个学名叫做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

目录
相关文章
|
4月前
uni-app项目中如何添加百度统计代码?
uni-app项目中如何添加百度统计代码?
|
6月前
|
缓存 安全 Linux
百度搜索:蓝易云【Apache安装与优化教程。】
通过以上步骤,你已经成功安装和优化了Apache服务器。你可以根据自己的需求进行进一步的配置和调整,以满足你的网站的性能和安全需求。
214 2
|
6月前
|
缓存 安全 应用服务中间件
百度搜索:蓝易云【Nginx的搭建和优化详细教程。】
通过以上步骤,你已经成功搭建和优化了Nginx服务器。你可以根据自己的需求进行进一步的配置和调整,以满足你的网站的性能和安全需求。
261 3
|
8月前
|
Java 应用服务中间件 Linux
百度搜索:蓝易云【Linux系统安装tomcat并部署项目。]
Tomcat是一种常用的Web应用程序服务器,它是Apache软件基金会下的一个开源项目,能够处理Java Servlet和JSP等动态网页。
62 0
|
11月前
|
搜索推荐 前端开发 JavaScript
什么是百度优化?百度SEO优化解决方案
百度优化的解决方案不仅可以帮助企业提升网站在百度PC端的收录与关键词排名,也可以获得更好的移动端收录与关键词排名,从而达到品牌SEO推广及引流的目的。接下来小编为你详细分享什么是百度优化以及实用的解决方案,一起来看看吧。
598 0
|
2月前
|
Ubuntu Linux
百度搜索:蓝易云【Linux平台下构建TigerVNC项目教程】
至此,你已经成功在Linux平台下构建并安装了TigerVNC项目。现在你可以启动VNC服务器并通过VNC客户端连接到远程桌面。请注意,上述步骤仅适用于一般情况,具体的构建步骤可能会因为不同的系统环境和版本而有所不同。在实际操作中,可能还需要根据实际情况进行一些调整。
33 1
|
2月前
|
缓存 NoSQL PHP
百度搜索:蓝易云【如何使用PHP进行数据库索引优化?】
通过以上方法,你可以使用PHP进行数据库索引优化,提高数据库查询性能和整体应用性能。同时,定期维护数据库和优化查询语句也是保持数据库高性能的关键。
42 11
|
4月前
|
存储 缓存 运维
百度搜索:蓝易云【【运维】GitLab相关配置优化等】
需要根据实际情况和需求来优化GitLab的配置。可以参考GitLab官方文档和社区资源,以获取更详细和针对性的配置优化建议。
64 0
|
4月前
|
Java Docker 容器
百度搜索:蓝易云【Docker部署jar项目教程】
请注意,以上是一个基本的教程,具体的步骤可能因项目结构和需求而有所不同。您可能需要根据实际情况进行调整和配置。同时,确保您的系统已经正确安装并配置了Docker。
44 1
|
9月前
|
资源调度 JavaScript
vue项目:集成富文本编辑器 - 百度ueditor(vue-ueditor-wrap)
vue项目:集成富文本编辑器 - 百度ueditor(vue-ueditor-wrap)
268 0