android闹钟(二):整体布局和MainActivity

采用tabHost,每个功能都采用自定义LinearLayout。

activity_main.xml

<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"

    xmlns:tools="http://schemas.android.com/tools"

    android:layout_width="match_parent"

    android:layout_height="match_parent"

    tools:context="com.mytest.myclock.MainActivity" >



    <TabHost

        android:id="@+id/tabhost"

        android:layout_width="match_parent"

        android:layout_height="match_parent" >



        <LinearLayout

            android:layout_width="match_parent"

            android:layout_height="match_parent"

            android:orientation="vertical" >



            <TabWidget

                android:id="@android:id/tabs"

                android:layout_width="match_parent"

                android:layout_height="wrap_content" >

            </TabWidget>



            <FrameLayout

                android:id="@android:id/tabcontent"

                android:layout_width="match_parent"

                android:layout_height="match_parent" >



                <com.mytest.myclock.TimeView

                    android:id="@+id/tab_time"

                    android:layout_width="match_parent"

                    android:layout_height="match_parent"

                    android:orientation="vertical" >



                    <TextView

                        android:id="@+id/tv_time"

                        android:layout_width="fill_parent"

                        android:layout_height="fill_parent"

                        android:gravity="center"

                        android:textAppearance="?android:attr/textAppearanceLarge" />

                </com.mytest.myclock.TimeView>



                <com.mytest.myclock.AlarmView

                    android:id="@+id/tab_alarm"

                    android:layout_width="match_parent"

                    android:layout_height="match_parent"

                    android:orientation="vertical" >



                    <ListView

                        android:id="@+id/lv_alarm"

                        android:layout_width="match_parent"

                        android:layout_height="match_parent"

                        android:layout_weight="1" >

                    </ListView>



                    <Button

                        android:id="@+id/btn_add_alarm"

                        android:layout_width="wrap_content"

                        android:layout_height="wrap_content"

                        android:gravity="center"

                        android:text="@string/add_alarm" />

                </com.mytest.myclock.AlarmView>



                <com.mytest.myclock.TimerView

                    android:id="@+id/tab_timer"

                    android:layout_width="match_parent"

                    android:layout_height="match_parent"

                    android:orientation="vertical" >



                    <LinearLayout

                        android:layout_width="match_parent"

                        android:layout_height="wrap_content"

                        android:layout_weight="1"

                        android:orientation="horizontal" >



                        <EditText

                            android:id="@+id/timer_hour"

                            android:layout_width="0dp"

                            android:layout_height="wrap_content"

                            android:layout_weight="1"

                            android:inputType="number"

                            android:singleLine="true" />



                        <TextView

                            android:layout_width="wrap_content"

                            android:layout_height="wrap_content"

                            android:text=":"

                            android:textAppearance="?android:attr/textAppearanceLarge" />



                        <EditText

                            android:id="@+id/timer_mini"

                            android:layout_width="0dp"

                            android:layout_height="wrap_content"

                            android:layout_weight="1"

                            android:inputType="number"

                            android:singleLine="true" />



                        <TextView

                            android:layout_width="wrap_content"

                            android:layout_height="wrap_content"

                            android:text=":"

                            android:textAppearance="?android:attr/textAppearanceLarge" />



                        <EditText

                            android:id="@+id/timer_second"

                            android:layout_width="0dp"

                            android:layout_height="wrap_content"

                            android:layout_weight="1"

                            android:inputType="number"

                            android:singleLine="true" />

                    </LinearLayout>



                    <LinearLayout

                        android:layout_width="match_parent"

                        android:layout_height="wrap_content"

                        android:orientation="horizontal" >



                        <Button

                            android:id="@+id/btn_start_timer"

                            android:layout_width="wrap_content"

                            android:layout_height="wrap_content"

                            android:text="@string/start_timer" />



                        <Button

                            android:id="@+id/btn_stop_timer"

                            android:layout_width="wrap_content"

                            android:layout_height="wrap_content"

                            android:text="@string/stop_timer" />

                    </LinearLayout>

                </com.mytest.myclock.TimerView>

            </FrameLayout>

        </LinearLayout>

    </TabHost>



</FrameLayout>
View Code

 

MainActivity.java

package com.mytest.myclock;



import android.app.Activity;

import android.os.Bundle;

import android.view.Menu;

import android.view.MenuItem;

import android.widget.TabHost;



public class MainActivity extends Activity {



    private TabHost tabHost;

    

    @Override

    protected void onCreate(Bundle savedInstanceState) {

        super.onCreate(savedInstanceState);

        setContentView(R.layout.activity_main);

        // android:id="@android:id/tabhost"

        tabHost = (TabHost)findViewById(R.id.tabhost);

        tabHost.setup();

    

        tabHost.addTab(tabHost.newTabSpec("tabTime").setIndicator("时钟").setContent(R.id.tab_time));

        tabHost.addTab(tabHost.newTabSpec("tabAlarm").setIndicator("闹钟").setContent(R.id.tab_alarm));

        tabHost.addTab(tabHost.newTabSpec("tabTimer").setIndicator("计时器").setContent(R.id.tab_timer));

    }

}
View Code

 

你可能感兴趣的:(Activity)