public class AllFileBrowser extends Activity {
private int ScreenWIDTH;
private ListView listViewFile;
protected void onCreate(Bundle savedInstanceState) {
//获取屏幕像素宽度
DisplayMetrics dMetrics = new DisplayMetrics();
getWindowManager().getDefaultDisplay().getMetrics(dMetrics);
ScreenWIDTH = dMetrics.widthPixels;
listViewFile = (ListView) findViewById(R.id.listView);
}
@Override
public void onWindowFocusChanged(boolean hasFocus) {
super.onWindowFocusChanged(hasFocus);
listViewFile .getLayoutParams().width=ScreenWIDTH*6/9;//在代码中可以随意设置listview的宽度
}}