码迷,mamicode.com
首页 > 移动开发 > 详细

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

时间:2015-07-22 18:06:20      阅读:127      评论:0      收藏:0      [点我收藏+]

标签:

采用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

 

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

标签:

原文地址:http://www.cnblogs.com/2015android/p/4667962.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!