Android快速開發(1)

1.activity相互調用

logo.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                startActivity(new Intent("com.example.think.myapplication.DetailActivity"));
            }
        });
<activity
            android:name=".DetailActivity"
            android:label="@string/title_activity_detail"
            android:theme="@style/AppTheme">
            <intent-filter>
                <action android:name="com.example.think.myapplication.DetailActivity"/>
                <category android:name="android.intent.category.DEFAULT"/>
            </intent-filter>
</activity>

2.相對佈局

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout 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.example.think.myapplication.MainActivity">

    <RelativeLayout
        android:layout_width="match_parent"
        android:layout_height="50dp"
        android:layout_alignParentTop="true"
        android:id="@+id/relativeLayout">
        <TextView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_alignParentLeft="true"
            android:layout_centerVertical="true"
            android:layout_marginLeft="10dp"
            android:text="校內"
            android:textColor="#ee0b0b0b"
            android:textSize="18sp"
            android:id="@+id/textView" />



    </RelativeLayout>
    <LinearLayout
        android:orientation="vertical"
        android:layout_width="match_parent"
        android:layout_height="300dp"
        android:id="@+id/linearLayout1"
        android:layout_below="@+id/relativeLayout"
        android:layout_above="@+id/main_bottom"
        android:layout_alignParentEnd="true">

    </LinearLayout>
    <LinearLayout
        android:orientation="horizontal"
        android:layout_width="match_parent"
        android:layout_height="54dp"
        android:background="#ffffff"
        android:gravity="center_vertical"
        android:id="@+id/main_bottom"
        android:layout_alignParentBottom="true">
        <RelativeLayout
            android:id="@+id/re_weixin"
            android:layout_width="0dp"
            android:layout_height="match_parent"
            android:layout_weight="1"
            android:onClick="onTabClicked"
            android:padding="3dp" >

            <ImageView
                android:id="@+id/ib_weixin"
                android:layout_width="wrap_content"
                android:layout_height="28dp"
                android:layout_centerHorizontal="true"
                android:background="#ffffff"
                android:focusable="false"
                android:scaleType="centerInside"
                android:src="@mipmap/weixin_normal" />

            <TextView
                android:id="@+id/tv_weixin"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_below="@id/ib_weixin"
                android:layout_centerHorizontal="true"
                android:layout_marginTop="3dp"
                android:text="消息"
                android:textColor="#9A9A9A"
                android:textSize="12sp" />

            <TextView
                android:id="@+id/unread_msg_number"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_alignParentRight="true"
                android:layout_marginRight="10dp"
                android:gravity="center"
                android:text="7"
                android:textColor="@android:color/white"
                android:textSize="12sp" />
        </RelativeLayout>
        <RelativeLayout
            android:id="@+id/re_contact_list"
            android:layout_width="0dp"
            android:layout_height="match_parent"
            android:layout_weight="1"
            android:onClick="onTabClicked"
            android:padding="3dp" >

            <ImageView
                android:id="@+id/ib_contact_list"
                android:layout_width="wrap_content"
                android:layout_height="28dp"
                android:layout_centerHorizontal="true"
                android:background="#ffffff"
                android:focusable="false"
                android:scaleType="centerInside"
                android:src="@mipmap/contact_list_normal" />

            <TextView
                android:id="@+id/tv_contact_list"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_below="@id/ib_contact_list"
                android:layout_centerHorizontal="true"
                android:layout_marginTop="3dp"
                android:text="通訊錄"
                android:textColor="#9A9A9A"
                android:textSize="12sp" />

            <TextView
                android:id="@+id/unread_address_number"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_alignParentRight="true"
                android:layout_marginRight="10dp"
                android:gravity="center"
                android:text="7"
                android:textColor="@android:color/white"
                android:textSize="12sp" />
        </RelativeLayout>

        <RelativeLayout
            android:id="@+id/re_find"
            android:layout_width="0dp"
            android:layout_height="match_parent"
            android:layout_weight="1"
            android:onClick="onTabClicked"
            android:padding="3dp" >

            <ImageView
                android:id="@+id/ib_find"
                android:layout_width="wrap_content"
                android:layout_height="28dp"
                android:layout_centerHorizontal="true"
                android:background="#ffffff"
                android:focusable="false"
                android:scaleType="centerInside"
                android:src="@mipmap/find_normal" />

            <TextView
                android:id="@+id/tv_find"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_below="@id/ib_find"
                android:layout_centerHorizontal="true"
                android:layout_marginTop="3dp"
                android:text="發現"
                android:textColor="#9A9A9A"
                android:textSize="12sp" />
        </RelativeLayout>

        <RelativeLayout
            android:id="@+id/re_profile"
            android:layout_width="0dp"
            android:layout_height="match_parent"
            android:layout_weight="1"
            android:onClick="onTabClicked"
            android:padding="3dp" >

            <ImageView
                android:id="@+id/ib_profile"
                android:layout_width="wrap_content"
                android:layout_height="28dp"
                android:layout_centerHorizontal="true"
                android:background="#ffffff"
                android:focusable="false"
                android:scaleType="centerInside"
                android:src="@mipmap/profile_normal" />

            <TextView
                android:id="@+id/tv_profile"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_below="@id/ib_profile"
                android:layout_centerHorizontal="true"
                android:layout_marginTop="3dp"
                android:text="我"
                android:textColor="#9A9A9A"
                android:textSize="12sp" />
        </RelativeLayout>

    </LinearLayout>
    <View
        android:id="@+id/view_temp"
        android:layout_width="match_parent"
        android:layout_height="0.1dp"
        android:layout_above="@id/main_bottom"
        android:background="#d6d6d6" />
    <RelativeLayout
        android:id="@+id/fragment_container"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:layout_above="@id/view_temp" />


</RelativeLayout>

3.android mainifest application theme

轉自http://blog.csdn.net/feng88724/article/details/6457431

•android:theme="@android:style/Theme.Dialog"   將一個Activity顯示爲能話框模式  
•android:theme="@android:style/Theme.NoTitleBar"  不顯示應用程序標題欄  
•android:theme="@android:style/Theme.NoTitleBar.Fullscreen"  不顯示應用程序標題欄,並全屏  
•android:theme="Theme.Light"  背景爲白色  
•android:theme="Theme.Light.NoTitleBar"  白色背景並無標題欄   
•android:theme="Theme.Light.NoTitleBar.Fullscreen"  白色背景,無標題欄,全屏  
•android:theme="Theme.Black"  背景黑色  
•android:theme="Theme.Black.NoTitleBar"  黑色背景並無標題欄  
•android:theme="Theme.Black.NoTitleBar.Fullscreen"    黑色背景,無標題欄,全屏  
•android:theme="Theme.Wallpaper"  用系統桌面爲應用程序背景  
•android:theme="Theme.Wallpaper.NoTitleBar"  用系統桌面爲應用程序背景,且無標題欄  
•android:theme="Theme.Wallpaper.NoTitleBar.Fullscreen"  用系統桌面爲應用程序背景,無標題欄,全屏  
•android:theme="Translucent"  半透明  
•android:theme="Theme.Translucent.NoTitleBar" 半透明、無標題欄  
•android:theme="Theme.Translucent.NoTitleBar.Fullscreen" 半透明、無標題欄、全屏  
•android:theme="Theme.Panel"  
•android:theme="Theme.Light.Panel"  

4.創建菜單,並響應動作

   @Override
    public boolean onCreateOptionsMenu(Menu menu) {
        // Inflate the menu; this adds items to the action bar if it is present.
        //創建右上角菜單
        menu.add(1, RED, 0, "紅色");
        menu.add(1, GREEN, 1, "綠色");
        return true;
    }

    @Override
    public boolean onOptionsItemSelected(MenuItem item) {
        int itemId = item.getItemId();
        switch (itemId) {
            case RED:
                new AlertDialog.Builder(MainActivity.this).setTitle("hi")
                        .setMessage("red")
                        .setPositiveButton("ok", null).show();
                break;
            case GREEN:
                new AlertDialog.Builder(MainActivity.this).setTitle("hi")
                        .setMessage("green")
                        .setPositiveButton("ok", null).show();
                break;
        }
        return true;
    }

5.通知:toast

Toast.makeText(MainActivity.this, R.string.success, Toast.LENGTH_SHORT).show();

6.layout
1)fill_parent
設置一個構件的佈局爲fill_parent將強制性地使構件擴展,以填充佈局單元內儘可能多的空間。這跟Windows控件的dockstyle屬性大體一致。設置一個頂部佈局或控件爲fill_parent將強制性讓它佈滿整個屏幕。
2) wrap_content
設置一個視圖的尺寸爲wrap_content將強制性地使視圖擴展以顯示全部內容。以TextView和ImageView控件爲例,設置爲wrap_content將完整顯示其內部的文本和圖像。佈局元素將根據內容更改大小。設置一個視圖的尺寸爲wrap_content大體等同於設置Windows控件的Autosize屬性爲True。
3)match_parent
Android2.2中match_parent和fill_parent是一個意思 .兩個參數意思一樣,match_parent更貼切,於是從2.2開始兩個詞都可以用。那麼如果考慮低版本的使用情況你就需要用fill_parent了。

發佈了22 篇原創文章 · 獲贊 26 · 訪問量 7萬+
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章