首页 > 其他分享 >Gallery默认第一项居左解决方案

Gallery默认第一项居左解决方案

时间:2023-04-06 20:32:05浏览次数:40  
标签:parentView int spacing 默认 gallery item 第一项 Gallery


网上找的,暂时用不到没测试过。
Android 中的Gallery控件默认会将第一项居中显示,在某些场景会影响用户体验,分享一下居左的解决方案:

/**
* Align the first gallery item to the left.
*
* @param parentView The view containing the gallery widget (we assume the gallery width
* is set to match_parent)
* @param gallery The gallery we have to change
*/
private void alignGalleryToLeft(View parentView, Gallery gallery) {
int galleryWidth = parentView.getWidth();

// We are taking the item widths and spacing from a dimension resource because:
// 1. No way to get spacing at runtime (no accessor in the Gallery class)
// 2. There might not yet be any item view created when we are calling this
// function
int itemWidth = context.getResources()
.getDimensionPixelSize(R.dimen.gallery_item_width);
int spacing = context.getResources()
.getDimensionPixelSize(R.dimen.gallery_spacing);

// The offset is how much we will pull the gallery to the left in order to simulate
// left alignment of the first item
int offset;
if (galleryWidth <= itemWidth) {
offset = galleryWidth / 2 - itemWidth / 2 - spacing;
} else {
offset = galleryWidth - itemWidth - 2 * spacing;
}
offset = 0;

// Now update the layout parameters of the gallery in order to set the left margin
MarginLayoutParams mlp = (MarginLayoutParams) gallery.getLayoutParams();
mlp.setMargins(-offset, mlp.topMargin, mlp.rightMargin, mlp.bottomMargin);
}




http://androidit.diandian.com/post/b8c29a20-e368-11e0-94a3-782bcb32ff27



Android自定义Gallery,实现CoverFlow效果


http://bigcat.easymorse.com/?p=1391


标签:parentView,int,spacing,默认,gallery,item,第一项,Gallery
From: https://blog.51cto.com/u_5454003/6174098

相关文章

  • hive Serde(默认)
    Hive读文件机制首先调用InputFormat(默认TextFormat),返回一条一条的键值对记录(默认是一行对一行键值对)。然后用Serde(默认为LazySimpleSerde)的Deserializer,将一条记录的value根据分隔符切分为各个字段。HDFSfilesInputFileFormat<key,value>DeserizlizerRowobject......
  • 解决Abp设置DefaultLanguage默认语言不生效的问题
    @目录现象原因分析解决问题现象默认地,Abp的语言提供程序将返回的CultureInfo为En,在一些默认实现的接口(比如/api/TokenAuth/Authenticate)返回的错误信息是英文目标是改成简体中文显示,但是即便我们在AbpSettings表中加入了DefaultLanguage为"zh-Hans"AddSettingIfNotExists(L......
  • 如何对语音信箱的多个号码设置不同的默认值
    1.1如何对语音信箱的多个号码设置不同的默认值 MTK平台的机制是如果sim卡中有6F17这只文件,那么语音信息将会被保存在sim卡上,如果sim卡没有这只文件,语音信息则会被保存在nvram上。换sim卡时,会初始化手机上的语音信息栏位  如果sim卡支持语音信息的栏位......
  • 如何修改network profile的默认值
    Fun&Game下的JavaNetwork菜单可以设置全局的Javanetworkprofile值,如何修改这个值? [SOLUTION] 初始化javanetworkprofile会调用到jam_nw_create_setting(),该函数会按照传进来的mids_storage生成XXX_nw_settings.bin文件,这个文件可能是globalne......
  • 默认python3版本,python2没有pip2模块,解决方案
    python2.7没有pip模块,需要安装pip2/usr/bin/python2:Nomodulenamedpip 直接通过pip安装出错,python3.6已经导入了 解决方案:下载pip安装文件: curlhttps://bootstrap.pypa.io/pip/2.7/get-pip.py -oget-pip.py用python2安装: python2get-pip.py   ......
  • Win11右键菜单如何直接默认显示更多选项
    Win11右键菜单如何直接默认显示更多选项1、首先用鼠标右键点击“开始”按钮(或者按Win+X键),选择点击“Windows终端(管理员2、然后在终端应用程序里粘贴这串代码【reg.exeadd"HKCU\Software\Classes\CLSID\{86ca1aa0-34aa-4e8b-a509-50c905bae2a2}\InprocServer32"/f/......
  • nginx上传文件超出默认大小限制-附件,提示:413 Request Entity Too Large
    Nginx限制文件上传大小,相应配置参数:client_max_body_size注意:该参数在nginx.conf中默认是没有配置的,不配置的情况下,nginx默认限制请求附件大小为:1M。即:默认当你通过nginx代理上传附件,大于1M的文件时,浏览器会抛出如下异常。处理方式:找到nginx的配置文件nginx/conf/nginx.conf,......
  • nacos默认配置启动
    1.相关组件组件说明版本地址Nacos配置及注册中心https://github.com/alibaba/nacos/releasesps:SpringBoot、SpringCloud和nacos集成版本对应关系对照(版本若对应不上,应用可能会启动报错):https://github.com/alibaba/spring-cloud-alibaba/wiki/版本说明2.组件......
  • 项目一众筹网05_02_[树形开发]菜单管理、API文档发布到web服务器、配置文件里面修改to
    系列文章目录文章目录系列文章目录08-页面显示树形结构-前端-使用真实数据09-准备zTree的API文档(因为现在没有图标)==API文档发布到web服务器上去==配置文件里面修改tomcat的默认端口号(只需改动3个地方)10-前端-显示图标-分析思路(-页面显示树形结构)11-前端-显示图标-代码实现(-页面......
  • ppp拨号管理线路--自动检查默认脚本--优化版本1
    #!/bin/bashPppCheck(){ppp_interfaces=$(ipr|grep-o"\<ppp[0-9]\+\>"|awk-F'ppp''{print$2}'|sort-n|uniq|awk'BEGIN{ORS=""}{print"ppp"$NF}')forifacein$ppp_in......