類似html中的%width語法,android layout中也有相對應的layout_weight和weightSum.
<LinearLayout ... > <TextView ... android:layout_weight="1" /> <TextView ... android:layout_weight="1" /> <TextView ... android:layout_weight="1" /> </LinearLayout>
(... 省略)
<LinearLayout ... > <TextView ... android:layout_weight="1" /> <TextView ... android:layout_weight="1" /> <TextView ... android:layout_weight="1" /> </LinearLayout>
(... 省略)
In main.xml xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:orientation="vertical" android:layout_width="fill_parent"
android:layout_height="fill_parent">
<WebView
android:id="@+id/MyIE"
android:layout_width="fill_parent"
android:layout_height="fill_parent" />
</LinearLayout>
In AndroidManifest.xml
....
<uses-permission android:name="android.permission.INTERNET" />
...
WebView ie; @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main ); // 取得 WebView物件 ie = (WebView) findViewById( R.id.MyIE); // 取得 WebSettings物件 WebSettings webSettings = ie.getSettings(); // 支援JavaScript webSettings.setJavaScriptEnabled(true); // 支援Zoom webSettings.setSupportZoom(true); webSettings.setBuiltInZoomControls(true); }
@Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); Toast.makeText(this, "onCreate", Toast.LENGTH_LONG).show(); } @Override protected void onRestart() { // TODO Auto-generated method stub super.onRestart(); Toast.makeText(this, "onRestart", Toast.LENGTH_LONG).show(); } @Override protected void onStart() { // TODO Auto-generated method stub super.onStart(); Toast.makeText(this, "onStart", Toast.LENGTH_LONG).show(); } @Override protected void onResume() { // TODO Auto-generated method stub super.onResume(); Toast.makeText(this, "onResume", Toast.LENGTH_LONG).show(); } @Override protected void onPause() { // TODO Auto-generated method stub super.onPause(); Toast.makeText(this, "onPause", Toast.LENGTH_LONG).show(); } @Override protected void onStop() { // TODO Auto-generated method stub super.onStop(); Toast.makeText(this, "onStop", Toast.LENGTH_LONG).show(); } @Override protected void onDestroy() { // TODO Auto-generated method stub super.onDestroy(); Toast.makeText(this, "onDestroy", Toast.LENGTH_LONG).show(); }
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
requestWindowFeature(Window.FEATURE_NO_TITLE);
getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN);
setContentView(R.layout.main);
...
<application android:icon="@drawable/wusjp" android:label="@string/app_name" >
<activity
android:theme="@android:style/Theme.NoTitleBar"
...
>
...
activity>
application>LinearLayout mLinearLayout;
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
// Create a LinearLayout in which to add the ImageView
mLinearLayout = new LinearLayout(this);
// Instantiate an ImageView and define its properties
ImageView i = new ImageView(this);
i.setImageResource(R.drawable.my_image);
i.setAdjustViewBounds(true); // set the ImageView bounds to match the Drawable's dimensions
i.setLayoutParams(new Gallery.LayoutParams(LayoutParams.WRAP_CONTENT,
LayoutParams.WRAP_CONTENT));
// Add the ImageView to the layout and set the layout as the content view
mLinearLayout.addView(i);
setContentView(mLinearLayout);
}
AssetFileDescriptor afd = getAssets().openFd("test.MP3"); mp.setDataSource(afd.getFileDescriptor(),afd.getStartOffset(),afd.getLength()); mp.prepare(); mp.start();
afd.close();