Android頁面佈局(幀佈局)

幀佈局,簡單理解可以說是將各個頁面或圖片層疊放置,如例圖:



layout文件夾下面的xml文件(初學者要注意嘍:xml文件應該選擇FrameLayout 的xml文件哦!

<?xml version="1.0" encoding="utf-8"?>
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent" >

    <ImageView
        android:id="@+id/imageView1"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:scaleType="fitXY"
        android:background="@drawable/blog_title" />

    <ImageView
        android:id="@+id/imageView2"
        android:layout_width="80dp"
        android:layout_height="wrap_content"
        android:paddingLeft="2dp"
        android:paddingTop="6dp"
        android:layout_gravity="left"
        android:src="@drawable/find" />

    <TextView
         android:id="@+id/textView1"
         android:layout_width="wrap_content"
         android:layout_height="wrap_content"
android:paddingLeft="14dp"
        android:paddingTop="20dp"      
         android:text="@string/find" />

    <TextView
         android:id="@+id/textView2"
         android:layout_width="wrap_content"
         android:layout_height="wrap_content"
 android:paddingTop="20dp"
         android:layout_gravity="center_horizontal"
         android:text="@string/blog" />
      
        <TextView 
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:text="@string/loginname"
        android:paddingTop="70dp"/>
    <EditText
        android:id="@+id/uname"
        
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:paddingTop="100dp"
        android:hint="@string/uname"/>
    
    <TextView 
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:text="@string/password"
        android:paddingTop="140dp"/>
    <EditText
        android:id="@+id/pwd"
        
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:paddingTop="170dp"
        android:hint="@string/upassword"
        android:inputType="textPassword"/>
        
       <Button
           android:id="@+id/button1"
           android:layout_width="wrap_content"
           android:layout_height="wrap_content"
           android:layout_gravity="left"
           android:background="@drawable/regist1"
           android:paddingTop="220dp"
           android:text="@string/regist" />

       <Button
           android:id="@+id/button2"
           android:layout_width="wrap_content"
           android:layout_height="wrap_content"
           android:layout_gravity="right"
           android:paddingTop="220dp"
           android:background="@drawable/login1"
           android:text="@string/login" />

</FrameLayout>


AndroidManifest.xml文件

<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="com.derun.activity"
    android:versionCode="1"
    android:versionName="1.0" >


    <uses-sdk
        android:minSdkVersion="17"
        android:targetSdkVersion="19" />

    <application
        android:allowBackup="true"
        android:icon="@drawable/ic_launcher"
        android:label="@string/app_name"
        android:theme="@style/AppTheme" >
        
        <activity android:name=".Layout_blog" android:label="layout5">
            <intent-filter>
                <action android:name="android.intent.action.MAIN"/>
                <category android:name="android.intent.category.LAUNCHER"/>
            </intent-filter>
        </activity>
               
    </application>

</manifest>


java文件,Layout_blog.java文件


package com.derun.activity;

import android.app.Activity;
import android.os.Bundle;

public class Layout_blog extends Activity{

@Override
protected void onCreate(Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);

setContentView(R.layout.layout5);
}

}

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章