ACtivity作业

界面的布局和规划

*利用LinearLayout的布局来设置界面
*同时用到Button按钮的控件来布局页面
*适当的分配空间布局的协调性

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout 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:orientation="vertical">

    <EditText
        android:id="@+id/et"
        android:layout_width="match_parent"
        android:layout_height="0dp"
        android:layout_weight="1"
        android:gravity="bottom|center_horizontal"
        android:hint="请输入你的名字"/>
    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:orientation="horizontal">
        <Button
            android:id="@+id/bt_jr"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_marginLeft="10dp"
            android:layout_weight="1"
            android:onClick="onClick"
            android:text="进入评估"
            android:background="#DBD"/>

        <Button
            android:id="@+id/bt_tc"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_marginRight="10dp"
            android:layout_weight="1"
            android:onClick="onClick"
            android:text="退出"
            android:background="#DBDB"/>
    </LinearLayout>
    <TextView
        android:id="@+id/tv"
        android:layout_width="match_parent"
        android:layout_height="0dp"
        android:layout_weight="1"
        />
</LinearLayout>

第二个界面大的界面

*实现跳转界面的转换
*我用到了RadioGroup的来控制Button的布局
*其他的基本和第一个界面一样

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:orientation="vertical"
    android:layout_width="match_parent"
    android:layout_height="match_parent">
    <TextView
        android:id="@+id/tv2"
        android:layout_width="match_parent"
        android:layout_height="250dp"
        android:gravity="bottom|center_vertical"
        android:text=""/>
    <RadioGroup
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:orientation="horizontal">
    <Button
        android:id="@+id/bt_y"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="有"
        android:onClick="onClick"
        android:layout_weight="1"/>
        <Button
            android:id="@+id/bt_my"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="没有"
            android:onClick="onClick"
            android:layout_weight="1"/>
    </RadioGroup>
    <TextView
        android:layout_width="match_parent"
        android:layout_height="match_parent" />
</LinearLayout>

java代码的实现

*zuoye与zuoyeActivity之间的跳转实现
*java大多数是请教同学和上网查阅来完成的

package cn.edu.niit.zuoye;

import android.content.Intent;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.TextView;

public class zuoye extends AppCompatActivity {
    private EditText et;
    private Button bt_jr;
    private Button bt_tc;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_zuoye);
        et =(EditText)findViewById(R.id.et);
        bt_jr =(Button)findViewById(R.id.bt_jr);
        bt_tc =(Button)findViewById(R.id.bt_tc);
        String data="";
        Intent intent=getIntent();
        String sg=intent.getStringExtra("result");
        TextView tv=(TextView)findViewById(R.id.tv);
        data = sg;
        tv.setText(data);
    }
    public void onClick (View view) {
        switch (view.getId()) {
            case R.id.bt_jr:
                question();
                break;
            case R.id.bt_tc:
                finish();
                break;
    }
}
    private void question() {
        Intent intent=new Intent();
        intent.setClass(zuoye.this,zuoyeActivity.class);
        String text =et.getText().toString();
        intent.putExtra("name",text+"1+1=2?");
        startActivity(intent);
    }
}
```##另一个java代码
*zuoyeActivity的跳转连接
```javascript
package cn.edu.niit.zuoye;

import android.content.Intent;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.TextView;

public class zuoyeActivity extends AppCompatActivity{
    private TextView tv2;
    private Button bt_y;
    private Button bt_my;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_zuoye);
        bt_y=(Button)findViewById(R.id.bt_y);
        bt_my=(Button)findViewById(R.id.bt_my);
        tv2 = (TextView) findViewById(R.id.tv2);
    String data="";
    Intent intent=getIntent();
    String jacky=intent.getStringExtra("name");
    TextView tv2=(TextView)findViewById(R.id.tv2);
    data = jacky;
    tv2.setText(data);}

    public void onClick(View view) {
        switch (view.getId()) {
            case R.id.bt_y:
                main1();
                break;
            case R.id.bt_my:
                main2();
                break;
        }}

    private void main2() {
        Intent intent=new Intent();
        intent.setClass(zuoyeActivity.this,zuoye.class);
        String a1=bt_y.getText().toString();
        intent.putExtra("result","评估结果:"+a1);
        intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
        startActivity(intent);
    }

    private void main1() {
        Intent intent=new Intent();
        intent.setClass(zuoyeActivity.this,zuoye.class);
        String b1=bt_my.getText().toString();
        intent.putExtra("result","评估结果:"+b1);
        intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
        startActivity(intent);
    }
}
posted @ 2017-04-18 21:12  孙耀威  阅读(174)  评论(1编辑  收藏  举报