我有一個擴展ListFragment的Fragment,它在運行時添加到FrameLayout。 FrameLayout已經包含一個ImageView。如何從ListFragment中刪除透明度
當在運行時添加ListFragment時,我可以看到背景,我只想要一個純色。
main.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;
}
}
更新您的答案 - getListView()。setBackgroundColor(getResources()。getColor(R.color.list_background));因爲這確實幫助我找到了正確的方法。 – Neil
哦,是的,你是對的,從setBackgroundColor int是真正的顏色。 – theomega