主要的用到的控件: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. uwp开发:数据绑定——值转换器 的简单使用

    原文:uwp开发:数据绑定--值转换器 的简单使用 今天,我在做最近正在开发的“简影”uwp应用时遇到一个问题,其中有个栏目,叫做“画报”,是分组显示一组一组的 图片,每组图片在界面上只显示9个,点击 ...

  2. 中国2017 Google 开发者大会第二天简单回顾

    昨天早晨发布了第一天的开发者大会回顾文章后,就匆匆忙忙赶去会场继续享受高科技的盛宴,接下来简单回顾一下第二天的大会参与情况. 昨天早晨下着小雨,并带着微风,在外面还是挺冷的,这里不得不给工作人员点个赞 ...

  3. gitlab安装笔记三_Centos7安装GitLab

    系统版本是CentOS-7-x86_64-Everything-1804.iso,很多软件默认都有了,不需要安装 https://about.gitlab.com/install/#centos-7 ...

  4. 上不了名校?可以在 GitHub 上读他们的课程

    今天开始,全国各大区域的高考成绩陆续公布,又到了几家欢喜几家愁的时刻,如果你准备报考计算机相关专业,但是又由于分数不高而苦恼.别担心,在 GitHub 上有着大量的名校教学资源,即使上不了名校,也可以 ...

  5. select下拉箭头样式重置

    select{ appearance:none; -moz-appearance:none; -webkit-appearance:none; background: url("../ima ...

  6. ASP.NET MVC/Core表单提交后台模型二级属性验证问题

    起因 这个是网友在官网论坛的提问:https://fineui.com/bbs/forum.php?mod=viewthread&tid=22237 重新问题 本着务实求真的态度,我们先来复现 ...

  7. spring boot 2.x 系列 —— spring boot 整合 RabbitMQ

    文章目录 一. 项目结构说明 二.关键依赖 三.公共模块(rabbitmq-common) 四.服务消费者(rabbitmq-consumer) 4.1 消息消费者配置 4.2 使用注解@Rabbit ...

  8. 使用回调的方式实现中间件-laravel

    $app = function ($request) { echo $request . "\n"; return "项目运行中....."; }; // 现在 ...

  9. python小方法 随笔记

    1. 元组和列表的接收 s1,s2 = [,] print(s1,s2) # 执行结果: 1 2 s3,s4 = (,) print(s3,s4)# 执行结果: 3 4 2. 变量值的交换 a = b ...

  10. 高性能微服务网关.NETCore客户端Kong.Net开源发布

    前言 项目地址:https://github.com/lianggx/Kong.Net 你的支持使我们更加强大,请单击 star 让更多的 .NETCore 认识它. 拥抱开源的脚步,我们从来都是一直 ...