我想实现这种布局:
在我将显示许多 TextView 的地方,用户将能够水平滚动并且列表将捕捉到中心项目(我将能够检索)。
看起来我有几个选择,但没有一个是令人满意的。
首先我研究过HorizontalScrollView
,但它只做滚动而不是捕捉。
Gallery
已弃用,但看起来最有希望 - 我只需要getView
在适配器中覆盖:
@Override
public View getView(int position, View convertView, ViewGroup parent) {
TextView tv = convertView == null ? new TextView(getActivity()) : (TextView) convertView;
tv.setText(getItem(position));
tv.measure(0, 0);
int width = tv.getMeasuredWidth();
tv.setLayoutParams(new Gallery.LayoutParams(width + 100, 100));
return tv;
}
其他可用选项是ViewPager
,但看起来 ViewPager 更喜欢与 ViewPager 本身一样宽的视图。
使用有什么问题Gallery
吗?我真的不喜欢谷歌在不提供等效替代品的情况下弃用 View,但我担心在未来的 Android 版本中它会消失。