1. 程式人生 > >高級控件 下(一)

高級控件 下(一)

edr apk str android nbsp vertica app stop ice

1.計時器(Chronometer)
<!-- 給應用授權:改變震動的權限 -->
<uses-permission android:name="android.permission.VIBRATE"></uses-permission>
//取得震動服務
vb=(Vibrator) getApplication().getSystemService(Service.VIBRATOR_SERVICE);
//開始計時
bstart.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
ch.start();
vb.vibrate(new long[]{1000,1000,1000,2000}
, 0);
}
});
//停止計時
bstop.setOnClickListener(new OnClickListener() {

@Override
public void onClick(View v) {
ch.stop();
ch.setBase(SystemClock.elapsedRealtime());//復原

}
});
2.標簽組件方式一(TabHost)


TabHost tabHost=getTabHost();
//把內容XML綁定在tabhost中
LayoutInflater.from(this).inflate(R.layout.tabhost
, tabHost.getTabContentView(),true);
TabSpec ts1=tabHost.newTabSpec("tab1")
.setIndicator("選項一")
.setContent(R.id.tv011);
tabHost.addTab(ts1);

TabSpec ts2=tabHost.newTabSpec("tab2")
.setIndicator("選項二")
.setContent(R.id.tv022);
tabHost.addTab(ts2);

TabSpec ts3=tabHost.newTabSpec("tab3")
.setIndicator("選項三")
.setContent(R.id.tv033);
tabHost.addTab(ts3);

方式二
<?xml version="1.0" encoding="utf-8"?>
<TabHost xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
>

<LinearLayout
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:id="@+id/ll1"
>
<TextView
android:id="@+id/tv044"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="選項內容一"
android:textSize="20dp"
/>
<ImageView
android:src="@drawable/sss"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
></ImageView>

</LinearLayout>


</TabHost>

高級控件 下(一)