网上找的,暂时用不到没测试过。
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
分享到:
相关推荐
灰色居左html5企业网站模板,简洁大气,全套模板,DIV CSS布局,包含blog.html,contact.html,features.html,gallery.html,index.html,portfolio.html,single.html,skins.html等多个页面网站模板。
一句话调用动态生成标签个数的标签栏,并可以设置 标签居左或是居中或是居右显示,支持单选或者多选
Easyui tabs 标题居左,文字竖着
C#tabcontrol中标签居左显示重绘代码
单栏居左记事本风格网页模板_二栏 居左 记事本 个性 整站.zip单栏居左记事本风格网页模板_二栏 居左 记事本 个性 整站.zip
居左居右UILabel UILabel可以左右显示拉~
单栏居左记事本风格网页模板_二栏 居左 记事本 个性 整站.rar
单栏居左记事本风格网页模板_二栏 居左 记事本 个性 整站_html网站模板_网页源码移动端前端_H5模板_自适应响应.rar
灰色居左简洁大气的HTML5网站模板5490.zip
li内容居左显示,内容过长,超出部分自动隐藏,鼠标放在去显示全部
网页设计模板-灰色居左简洁大气的HTML5网站模板.zip
模糊背景黑色个人作品网页模板_灰色 黑色 高斯模糊 居左 个人 作品 展示 整站 个性 漂亮.zip模糊背景黑色个人作品网页模板_灰色 黑色 高斯模糊 居左 个人 作品 展示 整站 个性 漂亮.zip
图片的居中显示css有很多方法,但在很多情况下有的方法无效,无意发现这个系统的官方处理图片居中,居左,居右的css写法,喜欢的朋友可以收藏下哦
模糊背景黑色个人作品网页模板_灰色 黑色 高斯模糊 居左 个人 作品 展示 整站 个性 漂亮
模糊背景黑色个人作品网页模板_灰色 黑色 高斯模糊 居左 个人 作品 展示 整站 个性 漂亮.rar
灰色居左简洁大气的HTML5网站模板_灰色 html5 幻灯 菜单 设计 整站 大气 精品 作品 案例 企业 简洁.zip灰色居左简洁大气的HTML5网站模板_灰色 html5 幻灯 菜单 设计 整站 大气 精品 作品 案例 企业 简洁.zip
灰色居左简洁大气的HTML5网站模板_灰色 html5 简洁_h模板_自适应响应式源码.rar
4164灰色居左简洁大气的HTML5网站模板5490_企业网站模板PHP整站源码.zip.7z
更新了win11,不喜欢这个任务栏和右键菜单.恢复成window7模式。
灰色居左简洁大气的HTML5网站模板_灰色 html5 幻灯 菜单 设计 整站 大气 精品 作品 案例 企业 简洁.rar