图像导航滑块Android

时间:2015-09-03 06:28:49

标签: android image android-layout slider

我想在Android上复制iOS相机胶卷滑块。 功能是显示固定数量的缩略图,但能够滑过所有图像。

结果将是:

enter image description here

2 个答案:

答案 0 :(得分:0)

制作两个布局:一个用于将缩略图视图放在运行时,另一个用于自定义搜索栏。将搜索栏布局放在缩略图布局的顶部。使进度条透明,并使用当前缩略图作为搜索栏的拇指。将搜索栏的最大值设置为页数 - 1.确保两个布局的宽度相同。 将OnSeekBarChangeListener添加到搜索栏:

@Override
public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) {
    // Retrieve the thumbnail for the page
    // progress = page id, since the max value of the seek bar is restricted to the number of pages
    Bitmap thumbnail = getThumbnailForPage(int progress)
    if (thumbnail != null) {
        seekBar.setThumb(new BitmapDrawable(getResources(), thumbnail));
    }

    // Change the view pager to the page with id = progress
}

在运行时创建页面缩略图的ImageView,并将它们添加到缩略图布局中。您的搜索栏布局应位于前台,否则您将无法单击该栏,也无法检测到进度更改。

答案 1 :(得分:0)

你应该结合水平的SCROLLVIEW和LINEARLAYOUT以及GRIDVIEW来实现你想要的!将网格视图放在linearlayout中,并将线性布局放在水平滚动视图中;

然后设置适配器!统计数据的数量!之后,您应该计算所需的宽度,以显示您的所有项目!例如,你想要显示8项!每个宽度为100dp。所以所需的宽度将是800dp!那么你应该添加这些代码行

yourGridView.setNumColumns(8);
LinearLayout.LayoutParams lp=new LinearLayout.LayoutParams(800, ViewGroup.LayoutParams.MATCH_PARENT);
yourGridView.setLayoutParams(lp);

dnt忘记在xml中将线性布局的宽度设置为WRAP_CONTENT!

*重要提示* 据我所知,通过这样做,gridview无法进行垃圾收集,因为Scroll View不支持这样的事情并且您的网格视图嵌套在其中!所以dnt对很多图像使用这种方法,否则你会得到HEAP SIZE错误!