获取手机屏幕大小:
DisplayMetrics dm = new DisplayMetrics(); getWindowManager().getDefaultDisplay().getMetrics(dm); String str = "x"+dm.widthPixels+"y"+dm.heightPixels);
ListView的使用:
<ListView android:id="@+id/ListView01" android:layout_width="fill_parent" android:layout_height="wrap_content"/>
public ListView lv;
lv = (ListView)findViewById(R.id.ListView01);
ArrayAdapter<String> ad = new ArrayAdapter<String>(this, android.R.layout.simple_list_item_1,st); lv.setAdapter(ad); lv.setOnItemClickListener(new OnItemClickListener() { public void onItemClick(AdapterView<?> arg0, View arg1, int arg2, long arg3) { Toast.makeText(TestActivity02Activity.this, arg2+".", Toast.LENGTH_LONG).show(); } });
运用style控制Activity样式:
<TextView style="@style/testcolor01" //设置style在style.xml中对应名称 android:layout_height="wrap_content" android:layout_width="fill_parent" android:text="测试style样式控制" /> <TextView style="@style/testcolor02" android:layout_width="fill_parent" android:layout_height="wrap_content" android:text="测试中....." />
在values文件夹下新建一style.xml文件
<?xml version="1.0" encoding="UTF-8"?> <resources> <style name="testcolor01"> <item name="android:textColor">#F00</item> </style> <style name="testcolor02"> <item name="android:textColor">#000</item> <item name="android:background">#FFF</item> </style> </resources>