【Android UI】侧滑栏的使用(HorizontalScrollView控件的使用)
主要的用到的控件: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控件的使用)的更多相关文章
- Android自定义控件View(三)组合控件
不少人应该见过小米手机系统音量控制UI,一个圆形带动画效果的音量加减UI,效果很好看.它是怎么实现的呢?这篇博客来揭开它的神秘面纱.先上效果图 相信很多人都知道Android自定义控件的三种方式,An ...
- Android下拉涮新第三方通用控件
Android下拉涮新第三方通用控件https://github.com/chrisbanes/Android-PullToRefresh Pull To Refresh Views for Andr ...
- WPF里面多线程访问UI线程、主线程的控件
如果出现以下错误:调用线程无法访问此对象,因为另一个线程拥有该对象. 你就碰到多线程访问UI线程.主线程的控件的问题了. 先占位.
- Android 图片混排富文本编辑器控件
概述 一个Android 图片混排富文本编辑器控件(仿兴趣部落) 详细 代码下载:http://www.demodashi.com/demo/12032.html 一.一个Android 图片混排富文 ...
- Android音乐、视频类APP常用控件:DraggablePanel(2)
Android音乐.视频类APP常用控件:DraggablePanel(2) 附录文章1主要演示了如何使用DraggablePanel 的DraggableView.DraggablePanel ...
- Android音乐、视频类APP常用控件:DraggablePanel(1)
Android音乐.视频类APP常用控件:DraggablePanel(1) Android的音乐视频类APP开发中,常涉及到用户拖曳视频.音乐播放器产生一定交互响应的设计需求,最典型的以You ...
- 【Android】11.0 UI开发(二)——列表控件ListView的简单实现1
************************ 转载请注明出处:https://www.cnblogs.com/xiaofu007/p/10342462.html ***************** ...
- 【Android】15.0 UI开发(六)——列表控件RecyclerView的网格布局排列实现
1.0 列表控件RecyclerView的网格布局排列实现,关键词GridLayoutManager. LinearLayoutManager 实现顺序布局 GridLayoutManager 实现网 ...
- 【Android】14.0 UI开发(五)——列表控件RecyclerView的瀑布布局排列实现
1.0 列表控件RecyclerView的瀑布布局排列实现,关键词StaggeredGridLayoutManager LinearLayoutManager 实现顺序布局 GridLayoutMan ...
随机推荐
- GzipStream的简单使用压缩和解压
压缩和解压都需要用到三个流实例,分别是文件读取流.文件写入流.压缩流. 读取流和写入流有多种形式,压缩流就一种GzipStream. 不同的是对于压缩,是需要用文件写入流作为创建压缩流实例的参数, 压 ...
- Hadoop分布式文件系统
在一个经典的数据架构中,Hadoop是处理复杂数据流的核心.数据从各种系统中收集而来,并汇总导入到Hadoop分布式文件系统HDFS中,然后通过MapReduce或者其它基于MapReduce封装的语 ...
- Linux命令执行顺序与管道命令
命令执行顺序控制 顺序执行多条命令:command1;command2;command3... 有选择执行命令:which command1 && command2 || comman ...
- MQTT-CN MQTT协议中文版
欢迎任何形式的转载,但请务必注明出处:http://www.cnblogs.com/liangjingyang 项目地址:https://github.com/liangjingyang/MQTT-C ...
- SQL 游标知识整理
游标声明格: declare 游标名称 cursor (游标关键字) for 游标操作对象(select * from 表名称)游标使用: open 游标名称; fetch first from 游标 ...
- client,offset,scroll系列
client(客户端),offset(偏移),scroll(滚动)1.client系列 clientTop 内容区域到边框顶部的距离 ,说白了,就是边框的高度 clientLeft 内容区域到边框左部 ...
- ansible(一)
一.目的 代码发布系统 二.准备工作:干净的虚拟机准备4个 准备一个虚拟机后克隆出另外三个,注意,克隆前要将虚拟机关机 三.可以用来代码发布的工具 puppet ansible slatstack 四 ...
- ZooKeeper学习第六期---ZooKeeper机制架构(转)
转载来源:https://www.cnblogs.com/sunddenly/p/4133784.html 一.ZooKeeper权限管理机制 1.1 权限管理ACL(Access Control L ...
- 高并发 Nginx+Lua OpenResty系列(9)——HTTP服务
此处我说的HTTP服务主要指如访问京东网站时我们看到的热门搜索.用户登录.实时价格.实时库存.服务支持.广告语等这种非Web页面,而是在Web页面中异步加载的相关数据.这些服务有个特点即访问量巨大.逻 ...
- 微信商城小程序 带java后台源码
微信小程序商城(Java版) 技术选型 1 后端使用技术 1.1 spring-web-4.0.2.RELEASE 1.2 mybatis3.2.8 1.3 shiro1.2.3 1.4 servle ...