我有个问题。我想将我的列表视图的背景颜色设置为白色,但只有行的背景颜色会发生变化。如何让背景填满整个屏幕?这是我的代码:
public class MyAdapter extends ArrayAdapter<String> {
private final Context context;
private final String[] values;
public MyAdapter(Context context, String[] values) {
super(context, R.layout.list_view, values);
this.context = context;
this.values = values;
}
@Override
public View getView(int position, View convertView, ViewGroup parent) {
LayoutInflater inflater = (LayoutInflater) context
.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
View rowView = inflater.inflate(R.layout.list_view, parent, false);
TextView textView = (TextView) rowView.findViewById(R.id.label);
Typeface tf = Typeface.createFromAsset(context.getAssets(), "fonts/chalkboardse.ttc");
textView.setTypeface(tf);
textView.setTextColor(Color.BLACK);
textView.setText(values[position]);
LinearLayout layout = (LinearLayout)rowView.findViewById(R.id.background);
layout.setBackgroundColor(Color.WHITE);
return rowView;
}
}
这是我的列表视图的 xml 文件:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="@+id/background" >
<TextView
android:id="@+id/label"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:padding="10dp"
android:textSize="20sp" >
</TextView>
</LinearLayout>
这是相应的活动:
public class AreaChooser extends ListActivity {
static final String [] FRUIT = new String [] { "Apple", "Pear"};
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setListAdapter(new MyAdapter(this, FRUIT));
}
}