首先感觸最深的:
因為照片的問題 ,導緻R檔案自動消失 。出現莫名的錯誤 是以 照片放到drawable中的時候,一定要記得把名字變成英文字母開頭 并且是小寫開頭的名稱。
階段一:布局檔案:
布局1、alert:
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:background="@drawable/photo1" >
<RadioGroup
android:layout_width="wrap_content"
android:layout_height="fill_parent" >
<RadioButton
android:id="@+id/radioButton1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/Bell1" />
<RadioButton
android:id="@+id/radioButton2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/Bell2" />
<RadioButton
android:id="@+id/radioButton3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/Bell3" />
<RadioButton
android:id="@+id/radioButton4"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/Bell4" />
</RadioGroup>
</LinearLayout>
布局2、datatime:
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@drawable/photo1"
android:orientation="vertical" >
<DatePicker
android:id="@+id/date"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
<RadioGroup
android:layout_width="fill_parent"
android:layout_height="wrap_content" >
<RadioButton
android:id="@+id/radioButton1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/Bell1" />
<RadioButton
android:id="@+id/radioButton2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/Bell2" />
<RadioButton
android:id="@+id/radioButton3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/Bell3" />
<RadioButton
android:id="@+id/radioButton4"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/Bell4" />
</RadioGroup>
</LinearLayout>
布局3、profiles:
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@drawable/photo1" >
<TextView
android:id="@+id/textView1"
android:layout_width="wrap_content"
android:layout_height="80dp"
android:layout_alignLeft="@+id/textView2"
android:layout_alignParentTop="true"
android:layout_marginLeft="24dp"
android:layout_marginTop="57dp"
android:text="@string/name"
android:textAppearance="?android:attr/textAppearanceLarge" />
<TextView
android:id="@+id/textView2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_above="@+id/imageButton2"
android:layout_alignParentLeft="true"
android:layout_marginBottom="42dp"
android:layout_marginLeft="33dp"
android:text="音量:"
android:textAppearance="?android:attr/textAppearanceLarge" />
<ImageView
android:id="@+id/image"
android:layout_width="60dp"
android:layout_height="60dp"
android:layout_alignRight="@+id/textView2"
android:layout_below="@+id/imageButton1"
android:layout_marginTop="45dp"
android:background="#f7de6a"
android:src="@android:drawable/ic_lock_silent_mode" />
<ImageView
android:id="@+id/imageView3"
android:layout_width="60dp"
android:layout_height="60dp"
android:layout_alignTop="@+id/image"
android:layout_centerHorizontal="true"
android:background="#f7de6a"
android:src="@android:drawable/ic_lock_silent_mode_off" />
<SeekBar
android:id="@+id/seekBar1"
android:layout_width="150dp"
android:layout_height="wrap_content"
android:layout_alignLeft="@+id/imageView3"
android:layout_alignTop="@+id/textView2" />
<ImageButton
android:id="@+id/imageButton1"
android:layout_width="80dp"
android:layout_height="80dp"
android:layout_alignRight="@+id/textView1"
android:layout_below="@+id/textView2"
android:background="#aaa9a6"
android:src="@android:drawable/ic_media_previous" />
<ImageButton
android:id="@+id/imageButton2"
android:layout_width="80dp"
android:layout_height="80dp"
android:layout_centerVertical="true"
android:layout_marginLeft="28dp"
android:layout_toRightOf="@+id/imageButton1"
android:background="#aaa9a6"
android:src="@android:drawable/ic_media_next" />
<ImageView
android:id="@+id/imageView2"
android:layout_width="60dp"
android:layout_height="60dp"
android:layout_alignParentRight="true"
android:layout_alignTop="@+id/imageView3"
android:layout_marginRight="24dp"
android:background="#f7de6a"
android:src="@android:drawable/btn_star" />
<ImageView
android:id="@+id/imageView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignTop="@+id/textView1"
android:layout_toRightOf="@+id/imageView3"
android:src="@drawable/photo4" />
</RelativeLayout>
階段2、功能實作
利用TabHost 頁籤 實作布局界面的簡化
首先三個activity:
1、AlertActivity:
package cn.cn.Tab.tab_list;
import android.os.Bundle;
import android.app.Activity;
import android.view.Menu;
public class AlertActivity extends Activity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_alert);
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.alert, menu);
return true;
}
}
2、DataActivity:
package cn.cn.Tab.tab_list;
import android.os.Bundle;
import android.app.Activity;
import android.view.Menu;
public class DataActivity extends Activity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_data);
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.data, menu);
return true;
}
}
3、ProfileActivity:
package cn.cn.Tab.tab_list;
import android.os.Bundle;
import android.app.Activity;
import android.view.Menu;
public class PhofilesActivity extends Activity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_phofiles);
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.phofiles, menu);
return true;
}
}
package cn.cn.Tab.tab_list;
import android.os.Bundle;
import android.app.TabActivity;
import android.content.Intent;
import android.content.res.Resources;
import android.view.Menu;
import android.widget.TabHost;
public class MainActivity extends TabActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
//setContentView(R.layout.activity_main);
Resources re = getResources();
TabHost tabhost = getTabHost();
Intent intent1 = new Intent();
intent1.setClass(this, AlertActivity.class);
Intent intent2 = new Intent();
intent2.setClass(this, DataActivity.class);
Intent intent3 = new Intent();
intent3.setClass(this, PhofilesActivity.class);
TabHost.TabSpec tab1 = tabhost.newTabSpec("tab1")
.setIndicator(null, re.getDrawable(R.drawable.photo2))
.setContent(intent1);
TabHost.TabSpec tab2 = tabhost.newTabSpec("tabo2")
.setIndicator(null, re.getDrawable(R.drawable.photo3))
.setContent(intent2);
TabHost.TabSpec tab3 = tabhost.newTabSpec("tab03")
.setIndicator(null, re.getDrawable(R.drawable.photo4))
.setContent(intent3);
tabhost.addTab(tab1);
tabhost.addTab(tab2);
tabhost.addTab(tab3);
tabhost.setCurrentTab(2);
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.main, menu);
return true;
}
}