主要的用到的控件:HorizontalScrollView

主要的功能:把几张图片解析成一张图片,在一个容器中呈现。

布局文件xml

side_bar_scollview.xml//显示view的容器

<?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"> <HorizontalScrollView
android:id="@+id/MyScrollView"
android:layout_width="match_parent"
android:layout_height="match_parent" > <LinearLayout
android:id="@+id/ll_layout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="horizontal" >
</LinearLayout> </HorizontalScrollView> </LinearLayout>

home.xml//显示的主页面

<?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"
android:background="@drawable/home_bg"> <TextView
android:id="@+id/textView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="主页" /> </LinearLayout>

menu.xml//显示的菜单页面

<?xml version="1.0" encoding="utf-8"?>
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@drawable/menu_bg"> <TextView
android:id="@+id/textView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="菜单" /> </FrameLayout>

MainActivity.java//主活动

package com.example.side_bar_scrollview;

import android.annotation.SuppressLint;
import android.app.Activity;
import android.os.Bundle;
import android.view.View;
import android.view.ViewTreeObserver.OnGlobalLayoutListener;
import android.widget.HorizontalScrollView;
import android.widget.LinearLayout; public class MainActivity extends Activity { private HorizontalScrollView scrollview;
private LinearLayout view_layout;
private int width;
private int height;
private View home_view;
private View menu_view;
private float rate=0.4f; @Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
//关联界面ID
setContentView(R.layout.side_bar_scollview);
//关联控件ID
scrollview=(HorizontalScrollView) findViewById(R.id.MyScrollView);
view_layout=(LinearLayout) findViewById(R.id.ll_layout);
//监听布局
MyLayoutListener();
//隐藏滚动条
scrollview.setHorizontalScrollBarEnabled(false);
} /**
* 监听布局的变化
* 1.getViewTreeObserver --- view事件的观察者
* 2.addOnGlobalLayoutListener
* 当在一个视图树中全局布局发生改变或者视图树中的某个视图的可视状态发生改变时,
* 所要调用的回调函数的接口类
*
*/
private void MyLayoutListener(){ scrollview.getViewTreeObserver().addOnGlobalLayoutListener(
new OnGlobalLayoutListener() { @Override
public void onGlobalLayout() {
// TODO Auto-generated method stub
//移除之前已经注册的全局布局的回调函数,使图片不会循环连在一起
view_layout.getViewTreeObserver()
.removeOnGlobalLayoutListener(this);
//获取最后一次调用measure()测量得到的scrollview的宽和高
height = scrollview.getMeasuredHeight();
width = scrollview.getMeasuredWidth();
//解析主页和菜单的布局
home_view=getLayoutInflater().inflate(R.layout.home,
null);
menu_view=getLayoutInflater().inflate(R.layout.menu,
null);
//添加view到view_layout
view_layout.addView(menu_view, (int)(width*rate), height);
view_layout.addView(home_view, width, height); }
}); } }

效果图:

【Android UI】侧滑栏的使用(HorizontalScrollView控件的使用)的更多相关文章

  1. Android自定义控件View(三)组合控件

    不少人应该见过小米手机系统音量控制UI,一个圆形带动画效果的音量加减UI,效果很好看.它是怎么实现的呢?这篇博客来揭开它的神秘面纱.先上效果图 相信很多人都知道Android自定义控件的三种方式,An ...

  2. Android下拉涮新第三方通用控件

    Android下拉涮新第三方通用控件https://github.com/chrisbanes/Android-PullToRefresh Pull To Refresh Views for Andr ...

  3. WPF里面多线程访问UI线程、主线程的控件

    如果出现以下错误:调用线程无法访问此对象,因为另一个线程拥有该对象. 你就碰到多线程访问UI线程.主线程的控件的问题了. 先占位.

  4. Android 图片混排富文本编辑器控件

    概述 一个Android 图片混排富文本编辑器控件(仿兴趣部落) 详细 代码下载:http://www.demodashi.com/demo/12032.html 一.一个Android 图片混排富文 ...

  5. Android音乐、视频类APP常用控件:DraggablePanel(2)

     Android音乐.视频类APP常用控件:DraggablePanel(2) 附录文章1主要演示了如何使用DraggablePanel 的DraggableView.DraggablePanel ...

  6. Android音乐、视频类APP常用控件:DraggablePanel(1)

     Android音乐.视频类APP常用控件:DraggablePanel(1) Android的音乐视频类APP开发中,常涉及到用户拖曳视频.音乐播放器产生一定交互响应的设计需求,最典型的以You ...

  7. 【Android】11.0 UI开发(二)——列表控件ListView的简单实现1

    ************************ 转载请注明出处:https://www.cnblogs.com/xiaofu007/p/10342462.html ***************** ...

  8. 【Android】15.0 UI开发(六)——列表控件RecyclerView的网格布局排列实现

    1.0 列表控件RecyclerView的网格布局排列实现,关键词GridLayoutManager. LinearLayoutManager 实现顺序布局 GridLayoutManager 实现网 ...

  9. 【Android】14.0 UI开发(五)——列表控件RecyclerView的瀑布布局排列实现

    1.0 列表控件RecyclerView的瀑布布局排列实现,关键词StaggeredGridLayoutManager LinearLayoutManager 实现顺序布局 GridLayoutMan ...

随机推荐

  1. 【Qt】一劳永逸解决UAC问题(修改mkspecs\win32-msvc2012\qmake.conf)

    如果你的程序跑在一个开启了UAC保护的系统中,而你的程序又没有"盾牌"的话,程序总是会受到各种阻挠的,比如读写文件,写注册表等. 有了"盾牌"的话就不会出现一些 ...

  2. How To Compile Qt with Visual Studio

    How To Compile Qt with Visual Studio FEBRUARY 1, 2011 This post is a step-by-step guide on how to co ...

  3. Notepad2(C语言+Windows消息写的,24592行代码)

    C语言+Windows消息写的,24592行代码 http://www.flos-freeware.ch/

  4. delphi 读写文本文件(函数比较全)

    需要两个按钮和两个Richedit控件,采用默认名称即可. procedure TForm1.Button1Click(Sender: TObject);  //写文件 var wText: Text ...

  5. Centos7安装Mysql-最方便、最快捷

    你想在Linux操作系统安装Mysql?你不想去官网下载再复制?,那就来看看我的方案,简单.快捷轻松安装.使用. 首先,检查安装情况         1.查看有没有安装过:           yum ...

  6. MAC和PHY的区别(网线上传递的是模拟信号)

    一块以太网网卡包括OSI(开方系统互联)模型的两个层.物理层和数据链路层.物理层定义了数据传送与接收所需要的电与光信号.线路状态.时钟基准.数据编码和电路等,并向数据链路层设备提供标准接口.数据链路层 ...

  7. win7、win8客户端 连接win2003上的sqlserver2005 速度超慢

    解决办法:开始运行,执行netsh interface tcp set global rss=disabled autotuninglevel=disabled.关闭TCP/IP协议的自动调谐功能.

  8. ajax,文件上传,分页器

    一.Ajax简介 AJAX(Asynchronous Javascript And XML)翻译成中文就是“异步Javascript和XML”.即使用Javascript语言与服务器进行异步交互,传输 ...

  9. Confluence安装、汉化及jira整合

    今天上午装了一下Confluence,刚开始装的时候成功了,成功后进入数据库配置阶段,本人想把jira和confluence整合一起用,刚开始提示数据库连接问题,后来一直问题提示Connection ...

  10. Spark学习之路(七)—— 基于ZooKeeper搭建Spark高可用集群

    一.集群规划 这里搭建一个3节点的Spark集群,其中三台主机上均部署Worker服务.同时为了保证高可用,除了在hadoop001上部署主Master服务外,还在hadoop002和hadoop00 ...