相对布局(作业)-- MarsChen Android 开发教程学习笔记
2014-09-03 11:18
696 查看
目标: 通过相对布局文件,实现如图所示布局:
在XML文件中代码:
在XML文件中代码:
<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" android:padding="20dp" android:paddingBottom="@dimen/activity_vertical_margin" android:paddingLeft="@dimen/activity_horizontal_margin" android:paddingRight="@dimen/activity_horizontal_margin" android:paddingTop="@dimen/activity_vertical_margin" tools:context="com.shumin.lbs03.MainActivity" > <TextView android:id="@+id/textView1" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_alignParentTop="true" android:layout_centerHorizontal="true" android:layout_marginTop="18dp" android:gravity="center|top" android:text="开始游戏" /> <ImageView android:id="@+id/imageView1" android:layout_below="@id/textView1" android:layout_height="wrap_content" android:layout_width="wrap_content" android:layout_margin="5dp" android:src="@drawable/eweibo"/> <ImageView android:id="@+id/imageView2" android:layout_height="wrap_content" android:layout_width="wrap_content" android:layout_below="@id/textView1" android:layout_toRightOf="@id/imageView1" android:layout_margin="5dp" android:src="@drawable/eweibo"/> <RadioGroup android:id="@+id/group1" android:layout_height="wrap_content" android:layout_width="wrap_content" android:layout_below="@id/imageView1" android:layout_alignLeft="@id/imageView1"> <RadioButton android:id="@+id/jiandao1" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_margin="3dp" android:text="剪刀" ></RadioButton> <RadioButton android:id="@+id/shitou1" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_margin="3dp" android:text="石头" ></RadioButton> <RadioButton android:id="@+id/bu1" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_margin="3dp" android:text="布" ></RadioButton> </RadioGroup> <RadioGroup android:id="@+id/group2" android:layout_height="wrap_content" android:layout_width="wrap_content" android:layout_below="@id/imageView2" android:layout_alignLeft="@id/imageView2"> <RadioButton android:id="@+id/jiandao2" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_margin="3dp" android:text="剪刀" ></RadioButton> <RadioButton android:id="@+id/shitou2" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_margin="3dp" android:text="石头" ></RadioButton> <RadioButton android:id="@+id/bu2" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_margin="3dp" android:text="布" ></RadioButton> </RadioGroup> <Button android:id="@+id/button" android:layout_height="wrap_content" android:layout_width="wrap_content" android:layout_below="@id/group2" android:layout_alignRight="@id/imageView2" android:text="开始"/></RelativeLayout>在JAVA文件中代码:
package com.shumin.lbs03; import android.app.Activity;import android.os.Bundle;import android.view.Menu;import android.view.MenuItem; public class MainActivity extends Activity { @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); } @Override public boolean onCreateOptionsMenu(Menu menu) { // Inflate the menu; this adds items to the action bar if it is present. getMenuInflater().inflate(R.menu.main, menu); return true; } @Override public boolean onOptionsItemSelected(MenuItem item) { // Handle action bar item clicks here. The action bar will // automatically handle clicks on the Home/Up button, so long // as you specify a parent activity in AndroidManifest.xml. int id = item.getItemId(); if (id == R.id.action_settings) { return true; } return super.onOptionsItemSelected(item); }}
相关文章推荐
- 单选按钮(作业)--MarsChen Android 开发教程学习笔记
- Service 初步 -- MarsChen Android 开发教程学习笔记
- 广播机制 -- MarsChen Android 开发教程学习笔记
- WiFi 网络操作(一)-- MarsChen Android 开发教程学习笔记
- Handelr(二上)-- MarsChen Android 开发教程学习笔记
- 文件下载 -- MarsChen Android 开发教程学习笔记
- SQLite 使用方法 -- MarsChen Android 开发教程学习笔记
- Activity 生命周期(一)-- MarsChen Android 开发教程学习笔记
- ProgressBar --MarsChen Android 开发教程学习笔记
- App Widget -- MarsChen Android 开发教程学习笔记
- Handler(一)--MarsChen Android 开发教程学习笔记
- 时间与日期--MarsChen Android 开发教程学习笔记
- Android应用开发学习笔记之相对布局
- ListView -- MarsChen Android 开发教程学习笔记
- SeekBar 和RatingBar --MarsChen Android 开发教程学习笔记
- Android 当中的线程-- MarsChen Android 开发教程学习笔记
- 程序调试 -- MarsChen Android 开发教程学习笔记
- LayoutAnimationController -- MarsChen Android 开发教程学习笔记
- 多选按钮(作业)--MarsChen Android 开发教程笔记
- Spinner -- MarsChen Android 开发教程学习笔记