我试图将ListView
变成可绘制的XML文件
我所做的就是我已将Item
中的每个ListView
变为BitmapDrawable
,并将array
全部变为LayerDrawable
所以我可以制作 ListAdapter adapter = listView.getAdapter();
View childView1 = adapter.getView(0, null, listView);
View childView2 = adapter.getView(1, null, listView);
View childView3 = adapter.getView(2, null, listView);
View childView4 = adapter.getView(3, null, listView);
childView1.measure(View.MeasureSpec.makeMeasureSpec(listView.getWidth(), View.MeasureSpec.EXACTLY), View.MeasureSpec.makeMeasureSpec(0, View.MeasureSpec.UNSPECIFIED));
childView1.layout(0, 0, childView1.getMeasuredWidth(), childView1.getMeasuredHeight());
childView2.measure(View.MeasureSpec.makeMeasureSpec(listView.getWidth(), View.MeasureSpec.EXACTLY), View.MeasureSpec.makeMeasureSpec(0, View.MeasureSpec.UNSPECIFIED));
childView2.layout(0, 0, childView2.getMeasuredWidth(), childView2.getMeasuredHeight());
childView3.measure(View.MeasureSpec.makeMeasureSpec(listView.getWidth(), View.MeasureSpec.EXACTLY), View.MeasureSpec.makeMeasureSpec(0, View.MeasureSpec.UNSPECIFIED));
childView3.layout(0, 0, childView3.getMeasuredWidth(), childView3.getMeasuredHeight());
childView4.measure(View.MeasureSpec.makeMeasureSpec(listView.getWidth(), View.MeasureSpec.EXACTLY), View.MeasureSpec.makeMeasureSpec(0, View.MeasureSpec.UNSPECIFIED));
childView4.layout(0, 0, childView4.getMeasuredWidth(), childView4.getMeasuredHeight());
childView1.setDrawingCacheEnabled(true);
childView1.buildDrawingCache();
childView2.setDrawingCacheEnabled(true);
childView2.buildDrawingCache();
childView3.setDrawingCacheEnabled(true);
childView3.buildDrawingCache();
childView4.setDrawingCacheEnabled(true);
childView4.buildDrawingCache();
Bitmap bmp1 = childView1.getDrawingCache().copy(Bitmap.Config.ARGB_8888, false);
Bitmap bmp2 = childView2.getDrawingCache().copy(Bitmap.Config.ARGB_8888, false);
Bitmap bmp3 = childView3.getDrawingCache().copy(Bitmap.Config.ARGB_8888, false);
Bitmap bmp4 = childView4.getDrawingCache().copy(Bitmap.Config.ARGB_8888, false);
BitmapDrawable bd1 = new BitmapDrawable(getResources(), bmp1);
BitmapDrawable bd2 = new BitmapDrawable(getResources(), bmp2);
BitmapDrawable bd3 = new BitmapDrawable(getResources(), bmp3);
BitmapDrawable bd4 = new BitmapDrawable(getResources(), bmp4);
BitmapDrawable drawables[] = {bd1, bd2, bd3, bd4};
LayerDrawable wow = new LayerDrawable(drawables);
root.setBackground(wow);
他们,而不是我作为背景。
像这样:
String hi[] = {"1", "2", "3", "4"};
ArrayList<String> hourArray = new ArrayList<>(Arrays.asList(hi));
hourArrayAdapter = new ArrayAdapter<>(this, R.layout.listitem_forecast, R.id.listitem_forecast_textview, hourArray);
listView = (ListView) findViewById(R.id.hourList);
listView.setAdapter(hourArrayAdapter);
但这是结果.......................................... ...................
任何建议都将不胜感激!
编辑:这是ListView ...
{{1}}