【问题标题】:Android ImageView with ListView, where ImageView scrolls slightly up when user tries to scroll down带有 ListView 的 Android ImageView,当用户尝试向下滚动时,ImageView 会稍微向上滚动
【发布时间】:2015-05-21 08:29:26
【问题描述】:
我必须创建一个看起来像这样的布局。它有一个图像视图,下面有一个列表视图。
我想要的是,当用户尝试向下滚动时,首先图像视图将向上移动以使图像视图的一小部分可见,从而使分配给列表视图的空间更多。只有在图像向上滚动到其新位置之后,列表视图才会开始滚动,而不是在那之前。
再次,在向上滚动时,一旦用户到达列表视图的顶部,图像视图应该再次向下滚动以完全可见。
关于如何实现这一点的任何建议?谢谢。
【问题讨论】:
标签:
android
image
listview
view
scroll
【解决方案1】:
您可以查看:https://github.com/Gnod/ParallaxListView
否则:https://github.com/Frank-Zhu/PullZoomView
mListView = (ParallaxScollListView) findViewById(R.id.layout_listview);
View header = LayoutInflater.from(this).inflate(R.layout.listview_header, null);
mImageView = (ImageView) header.findViewById(R.id.layout_header_image);
mListView.setParallaxImageView(mImageView);
mListView.addHeaderView(header);
ArrayAdapter<String> adapter = new ArrayAdapter<String>(this,
android.R.layout.simple_expandable_list_item_1,
new String[]{
"First Item",
"Second Item",
"Third Item",
"Fifth Item",
"Sixth Item",
"Seventh Item",
"Eighth Item",
"Ninth Item",
"Tenth Item",
"....."
}
);
mListView.setAdapter(adapter);
【解决方案2】:
你试过吗?
制作一个自定义 ListView。
另一个布局 (layout_header.xml) 包含单个图像视图 (headImage)。将此布局设置为列表视图的第一个对象。
并制作一个customListView.java。您的 customlistView.java 将如下所示。我跳过了基本部分,希望你能填补它。
public class CustomListView extends ArrayAdapter<String> {
public CustomList(Activity context, etc params) {
**Your Code
}
@Override
public View getView(int position,View view, ViewGroup parent){
View rowView;
if (position == 0){
LayoutInflater inflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
view = inflater.inflate(R.layout.layout_header, parent, false);
ImageView bannerImage = (ImageView)rowView.findViewById(R.id.headImage);
问题是顶部的图像会被列表完全向上滚动