2017.3.21安卓作业
先弄个界面布局
大概是这个样子
这样比较省事
名字都是一样的
选择你的游戏

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context="com.example.hp.myapplication1.MainActivity"
android:orientation="vertical">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textColor="@android:color/holo_blue_dark"
android:layout_gravity="center"
android:ellipsize="marquee"
android:focusable="true"
android:focusableInTouchMode="true"
android:marqueeRepeatLimit="marquee_forever"
android:scrollHorizontally="true"
android:scrollbars="horizontal"
android:singleLine="true"
android:text="Please choose a game"
android:textSize="30dp"
android:id="@+id/keyi" />
<ImageView
android:layout_width="200dp"
android:layout_height="140dp"
android:layout_gravity="center"
android:id="@+id/tupian"
tools:layout_editor_absoluteY="0dp"
tools:layout_editor_absoluteX="0dp" />
<RadioGroup
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="20dp"
android:orientation="vertical"
android:id="@+id/game"
>
<RadioGroup
android:layout_marginTop="40dp"
android:id="@+id/pl"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center"
android:orientation="horizontal"
>
<RadioButton
android:id="@+id/game1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:checked="true"
android:text="game1"
android:textSize="20sp"
/>
<RadioButton
android:id="@+id/game2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="game2"
android:textSize="20sp"/>
<RadioButton
android:id="@+id/game3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="game3"
android:textSize="20sp"/>
</RadioGroup>
<RadioGroup
android:id="@+id/pl2"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center"
android:orientation="horizontal"
>
<RadioButton
android:id="@+id/game4"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="game4"
android:textSize="20sp"
/>
<RadioButton
android:id="@+id/game5"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="game5"
android:textSize="20sp"/>
<RadioButton
android:id="@+id/game6"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="game6"
android:textSize="20sp"/>
</RadioGroup>
</RadioGroup>
</LinearLayout>
然后关联JAVA
将定义该完成定义
将图片弄进去
把图片名字弄好
一一对应
完成了
package com.example.hp.myapplication1;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.widget.ImageView;
import android.widget.RadioButton;
import android.widget.RadioGroup;
import android.widget.TextView;
public class MainActivity extends AppCompatActivity {
private TextView txkeyi;
private RadioButton rbgame1;
private RadioButton rbgame2;
private RadioButton rbgame3;
private RadioButton rbgame4;
private RadioButton rbgame5;
private RadioButton rbgame6;
private RadioGroup plpl;
private RadioGroup plpl2;
private RadioGroup game;
private ImageView ivtupian;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
txkeyi = (TextView) findViewById(R.id.keyi);
rbgame1 = (RadioButton) findViewById(R.id.game1);
rbgame2 = (RadioButton) findViewById(R.id.game2);
rbgame3 = (RadioButton) findViewById(R.id.game3);
rbgame4 = (RadioButton) findViewById(R.id.game4);
rbgame5 = (RadioButton) findViewById(R.id.game5);
rbgame6 = (RadioButton) findViewById(R.id.game6);
plpl = (RadioGroup) findViewById(R.id.pl);
plpl2 = (RadioGroup) findViewById(R.id.pl2);
game = (RadioGroup) findViewById(R.id.game);
ivtupian = (ImageView) findViewById(R.id.tupian);
plpl.setOnCheckedChangeListener(new RadioGroup.OnCheckedChangeListener() { //监听rgrg RadioGroup组
@Override
public void onCheckedChanged(RadioGroup radioGroup, int i) {
if (rbgame1.isChecked()) {
ivtupian.setImageResource(R.drawable.game1);
plpl2.clearCheck();
}
if (rbgame2.isChecked()) {
ivtupian.setImageResource(R.drawable.game2);
plpl2.clearCheck();
}
if (rbgame3.isChecked()) {
ivtupian.setImageResource(R.drawable.game3);
plpl2.clearCheck();
}
}
});
plpl2.setOnCheckedChangeListener(new RadioGroup.OnCheckedChangeListener() {
@Override
public void onCheckedChanged(RadioGroup radioGroup, int i) {
if (rbgame4.isChecked()) {
ivtupian.setImageResource(R.drawable.game4);
plpl.clearCheck();
}
if (rbgame5.isChecked()) {
ivtupian.setImageResource(R.drawable.game5);
plpl.clearCheck();
}
if (rbgame6.isChecked()) {
ivtupian.setImageResource(R.drawable.game6);
plpl.clearCheck();
}
}
});
}
}

然后就是第二个作业
<ImageView
android:layout_width="60dp"
android:layout_height="60dp"
android:layout_gravity="center_horizontal"
android:id="@+id/picture" />
<Button
android:layout_marginTop="300dp"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:text="退出"
android:id="@+id/button" />
布局,不要太简单呀嘿嘿嘿
然后关联JAVA
public class MainActivity extends AppCompatActivity {
private Button btbutton;
private ImageView ivtupian;
然后真的没时间做了
容我再想想好嘛
老师我先交作业吧
先这样吧。。。

浙公网安备 33010602011771号