实现一个个性的游戏界面:

【Android开发】范例2-个性游戏开始界面_relativelayout

素材:

【Android开发】范例2-个性游戏开始界面_relativelayout_02

实例代码:
MainActivity:

package com.example.test;


import android.app.Activity;
import android.os.Bundle;
import android.view.MotionEvent;
import android.view.View;
import android.view.View.OnTouchListener;
import android.widget.FrameLayout;


public class MainActivity extends Activity {

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);

}
}

res/drawable/文件夹下放置有background.jpg、img_top.jpg、in.png、exit.png、music.png、stop.png、setting.png图片待用



res/layout/main.xml:


<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical"
android:background="@drawable/background"
android:screenOrientation="landscape" >
<!-- 添加顶部图片 -->
<ImageView android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:scaleType="centerCrop"
android:layout_gravity="center_horizontal"
android:layout_weight="1"
android:src="@drawable/img_top"/>
<RelativeLayout android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="2"
android:id="@+id/relativelayout1">
<!-- 添加中间位置的图片按钮 -->
<ImageView android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/image1"
android:src="@drawable/in"
android:layout_centerInParent="true"/>
<!-- 添加上方显示的图片按钮 -->
<!-- alignLeft是和某个组件左边对其,而toLeftOf是在某控件左边 -->
<ImageView android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/image2"
android:src="@drawable/setting"
android:layout_above="@id/image1"
android:layout_alignRight="@id/image1"/>
<!-- 添加下方位置的图片按钮 -->
<ImageView android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/image3"
android:src="@drawable/stop"
android:layout_below="@id/image1"
android:layout_alignLeft="@id/image1"/>
<!-- 添加左侧位置的图片按钮 -->
<ImageView android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/image4"
android:src="@drawable/exit"
android:layout_toLeftOf="@id/image1"
android:layout_alignTop="@id/image1"/>
<!-- 添加右侧位置的图片按钮 -->
<ImageView android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/image5"
android:src="@drawable/music"
android:layout_toRightOf="@id/image1"
android:layout_alignTop="@id/image1"/>
</RelativeLayout>
</LinearLayout>