由网友(臭 流 氓 。)分享简介:我树立了图像列表视图背景下,如果我想与该项目滚动它,我该怎么办?I set a image as Listview background, if I want to scroll it with the item, what can I do?例如:1是背景,如果我滚动列表视图下,它会从for example...
我树立了图像列表视图背景下,如果我想与该项目滚动它,我该怎么办?
I set a image as Listview background, if I want to scroll it with the item, what can I do?
例如: 1是背景,如果我滚动列表视图下, 它会从
for example: 1 is the background, if I scroll Listview down, it will change from
1
-----1-----1--------
1 1
-1-------------1----
到
--------1----------
1 1
---1----------1----
1 1
也许我能扩展列表视图,并覆盖dispatchDraw, 但如果我用listFragment,我该怎么办? 任何人可以帮助我吗?
maybe I could extends listview and override dispatchDraw, but if I use listFragment, what can I do ? anybody help me?
推荐答案
在你活动的XML文件中定义的列表视图这样的:
In your Activity's XML file define the listview like this ::
(定义在该XML文件按照您的要求的财产)
(Define the property in this xml file as per your requirement)
<com.example.MyCustomListView
android:id="@+id/listview"
android:layout_width="fill_parent"
android:layout_height="fill_parent"/>
创建一个名为MyCustomListView一类::
Create one Class named 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);
}
}
希望这将解决您的问题:)
Hope this will solve your problem :)
相关推荐
最新文章