我有一个扩展 ListFragment 的片段,它在运行时添加到 FrameLayout。FrameLayout 已经包含一个 ImageView。
在运行时添加 ListFragment 时,我可以看到背景,我只想要纯色。
主要的.xml
<?xml version="1.0" encoding="utf-8"?>
<FrameLayout android:id="@+id/list_fragment"
android:layout_width="match_parent"
android:layout_height="match_parent">
<ImageView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:src="@drawable/icon"
android:tileMode="repeat" />
</FrameLayout>
我尝试了以下方法,但这只会在我滚动时变黑:
@Override
public void onActivityCreated(Bundle savedInstanceState) {
getListView().setCacheColorHint(R.color.list_background);
super.onActivityCreated(savedInstanceState);
}
在 R.color.list_background 中是:
<color name="list_background">#e2f4c7</color>
见下面的截图:
这是我的自定义适配器
public class DailyFlightsAdapter extends ArrayAdapter<DailyFlightVO> {
Context context;
int layoutResourceId;
ArrayList<DailyFlightVO> data = null;
public DailyFlightsAdapter(Context context, int layoutResourceId, ArrayList<DailyFlightVO> dailyFlights) {
super(context, layoutResourceId, dailyFlights);
this.layoutResourceId = layoutResourceId;
this.context = context;
this.data = dailyFlights;
}
@Override
public View getView(int position, View convertView, ViewGroup parent) {
View row = convertView;
FlightHolder holder = null;
if(row == null){
LayoutInflater inflator = ((Activity)context).getLayoutInflater();
row = inflator.inflate(layoutResourceId, parent, false);
holder = new FlightHolder();
holder.distance = (TextView)row.findViewById(R.id.distance);
holder.pilot = (TextView)row.findViewById(R.id.pilot);
row.setTag(holder);
}else{
holder = (FlightHolder)row.getTag();
}
DailyFlightVO vo = data.get(position);
holder.distance.setText(vo.getDistance());
holder.pilot.setText(vo.getPilot());
return row;
}
static class FlightHolder{
TextView distance;
TextView pilot;
}
}