我设置了一个图像作为Listview背景,如果我想随着项目滚动它,我该怎么办?
例如:
1是背景,如果我向下滚动Listview,
它将改变从
1
-----1-----1--------
1 1
-1-------------1----
to
--------1----------
1 1
---1----------1----
1 1
也许我可以扩展listview并覆盖dispatchDraw,
但如果我使用listFragment,我能做什么?
有人帮助我吗?
在您的 Activity 的 XML 文件中定义列表视图,如下所示::
(根据您的要求在此 xml 文件中定义属性)
<com.example.MyCustomListView
android:id="@+id/listview"
android:layout_width="fill_parent"
android:layout_height="fill_parent"/>
创建一个名为 MyCustomListView :: 的类
public class MyCustomListView extends ListView
{
private Bitmap background;
public MyCustomListView(Context context, AttributeSet attrs)
{
super(context, attrs);
background = BitmapFactory.decodeResource(getResources(), R.drawable.yourImageName);
}
@Override
protected void dispatchDraw(Canvas canvas)
{
int count = getChildCount();
int top = count > 0 ? getChildAt(0).getTop() : 0;
int backgroundWidth = background.getWidth();
int backgroundHeight = background.getHeight();
int width = getWidth();
int height = getHeight();
for (int y = top; y < height; y += backgroundHeight)
{
for (int x = 0; x < width; x += backgroundWidth)
{
canvas.drawBitmap(background, x, y, null);
}
}
super.dispatchDraw(canvas);
}
}
希望这能解决您的问题:)
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)