2015-09-03 131 views
1

我想复制Android上的iOS相机滚筒滑块。 功能将显示固定数量的缩略图,但可以滑动所有图像。图片导航滑块Android

,结果会是这样:

enter image description here

回答

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 
} 

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

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控件不能垃圾收集,因为滚动查看不支持这样嵌套在它的事情,你的网格视图!所以nt使用这种方法大量的图像,否则你会得到HEAP SIZE错误!