返回列表 發帖

土地面積換算 (一)

本帖最後由 tonyh 於 2019-3-16 17:24 編輯

完成如下之圖形介面:



values/strings.xml
  1. <resources>
  2.     <string name="app_name">土地面積換算</string>
  3.     <string name="title">1 坪 = 3.3058 平方公尺</string>
  4.     <string name="tv">輸入坪數</string>
  5.     <string name="btn1">清除</string>
  6.     <string name="btn2">換算</string>
  7. </resources>
複製代碼
layout/activity_main.xml
  1. <?xml version="1.0" encoding="utf-8"?>
  2. <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
  3.     xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent"
  4.     android:layout_height="match_parent" android:paddingLeft="@dimen/activity_horizontal_margin"
  5.     android:paddingRight="@dimen/activity_horizontal_margin"
  6.     android:paddingTop="@dimen/activity_vertical_margin"
  7.     android:paddingBottom="@dimen/activity_vertical_margin" tools:context=".MainActivity"
  8.     android:orientation="vertical"
  9.     android:weightSum="1">

  10.     <TextView
  11.         android:layout_width="match_parent"
  12.         android:layout_height="80dp"
  13.         android:text="@string/title"
  14.         android:id="@+id/textView"
  15.         android:textSize="22sp"
  16.         android:textColor="#000000"
  17.         android:gravity="center" />

  18.     <TextView
  19.         android:layout_width="wrap_content"
  20.         android:layout_height="wrap_content"
  21.         android:text="@string/tv"
  22.         android:id="@+id/textView2"
  23.         android:textSize="22sp"
  24.         android:textColor="#000000" />

  25.     <EditText
  26.         android:layout_width="match_parent"
  27.         android:layout_height="wrap_content"
  28.         android:id="@+id/editText"
  29.         android:textSize="22sp" />

  30.     <TextView
  31.         android:layout_width="match_parent"
  32.         android:layout_height="80dp"
  33.         android:id="@+id/textView3"
  34.         android:layout_gravity="center_horizontal"
  35.         android:textSize="22sp"
  36.         android:gravity="center_vertical"
  37.         android:layout_weight="0.08" />

  38.     <LinearLayout
  39.         android:orientation="horizontal"
  40.         android:layout_width="match_parent"
  41.         android:layout_height="wrap_content"
  42.         android:layout_gravity="center_horizontal"
  43.         android:gravity="right">

  44.         <Button
  45.             android:layout_width="wrap_content"
  46.             android:layout_height="wrap_content"
  47.             android:text="@string/btn1"
  48.             android:id="@+id/button"
  49.             android:textSize="18sp" />

  50.         <Button
  51.             android:layout_width="wrap_content"
  52.             android:layout_height="wrap_content"
  53.             android:text="@string/btn2"
  54.             android:id="@+id/button2"
  55.             android:textSize="18sp" />
  56.     </LinearLayout>

  57. </LinearLayout>
複製代碼
附件: 您需要登錄才可以下載或查看附件。沒有帳號?註冊

  1. package com.example.student.test1;
  2. import android.support.v7.app.AppCompatActivity;
  3. import android.os.Bundle;
  4. import android.view.View;
  5. import android.widget.EditText;
  6. import android.widget.TextView;


  7. public class MainActivity extends AppCompatActivity {

  8.     EditText input;
  9.     TextView result;
  10.     @Override
  11.     protected void onCreate(Bundle savedInstanceState) {
  12.         super.onCreate(savedInstanceState);
  13.         setContentView(R.layout.activity_main);
  14.         input = (EditText) findViewById(R.id.input);
  15.         result = (TextView) findViewById(R.id.textView2);
  16.     }

  17.     public void click(View view) {
  18.         int num = Integer.parseInt(input.getText().toString());
  19.         double r = num*3.3058;
  20.         result.setText("面積為: "+r+"平方公尺");
  21.     }

  22.     public void clean(View view) {
  23.         input.setText("");
  24.         result.setText("");
  25.     }
  26. }
複製代碼
EEEEEEEEEEEEELLLLLLLLLLLLLIIIIIIIIIIIII

TOP

本帖最後由 蕭澧邦 於 2019-3-23 14:36 編輯
  1. <?xml version="1.0" encoding="utf-8"?>
  2. <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
  3.     xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent"
  4.     android:layout_height="match_parent" android:paddingLeft="@dimen/activity_horizontal_margin"
  5.     android:paddingRight="@dimen/activity_horizontal_margin"
  6.     android:paddingTop="@dimen/activity_vertical_margin"
  7.     android:paddingBottom="@dimen/activity_vertical_margin" tools:context=".MainActivity"
  8.     android:orientation="vertical"
  9.     android:weightSum="1">

  10.     <TextView
  11.         android:layout_width="match_parent"
  12.         android:layout_height="wrap_content"
  13.         android:text="@string/title"
  14.         android:id="@+id/textView1"
  15.         android:textSize="22sp"
  16.         android:textColor="#000000"
  17.         android:gravity="center"
  18.         android:layout_weight="0.08"
  19.         android:layout_gravity="center_horizontal" />

  20.     <TextView
  21.         android:layout_width="match_parent"
  22.         android:layout_height="wrap_content"
  23.         android:text="@string/tv"
  24.         android:id="@+id/textView2"
  25.         android:textSize="22sp"
  26.         android:textColor="#000000"
  27.         android:layout_marginTop="20dp" />

  28.     <EditText
  29.         android:layout_width="match_parent"
  30.         android:layout_height="wrap_content"
  31.         android:id="@+id/editText"
  32.         android:textSize="22sp"
  33.         android:inputType="numberDecimal" />

  34.     <TextView
  35.         android:layout_width="match_parent"
  36.         android:layout_height="80dp"
  37.         android:id="@+id/textView3"
  38.         android:layout_gravity="center_horizontal"
  39.         android:textSize="22sp"
  40.         android:gravity="center_vertical"
  41.         android:layout_weight="0.08" />

  42.     <LinearLayout
  43.         android:orientation="horizontal"
  44.         android:layout_width="match_parent"
  45.         android:layout_height="wrap_content"
  46.         android:layout_gravity="center_horizontal"
  47.         android:gravity="right">

  48.         <Button
  49.             android:layout_width="wrap_content"
  50.             android:layout_height="wrap_content"
  51.             android:text="@string/btn1"
  52.             android:id="@+id/button1"
  53.             android:textSize="18sp" />

  54.         <Button
  55.             android:layout_width="wrap_content"
  56.             android:layout_height="wrap_content"
  57.             android:text="@string/btn2"
  58.             android:id="@+id/button2"
  59.             android:textSize="18sp" />
  60.     </LinearLayout>

  61. </LinearLayout>
複製代碼
  1. <resources>
  2.     <string name="app_name">土地面積換算</string>
  3.     <string name="title">1 坪 = 3.3058 平方公尺</string>
  4.     <string name="tv">輸入坪數</string>
  5.     <string name="btn1">清除</string>
  6.     <string name="btn2">換算</string>
  7. </resources>
複製代碼
  1. package com.example.shou6.myapplication;
  2. import android.support.v7.app.AppCompatActivity;
  3. import android.os.Bundle;
  4. import android.view.View;
  5. import android.widget.Button;
  6. import android.widget.EditText;
  7. import android.widget.TextView;


  8. public class MainActivity extends AppCompatActivity {

  9.     private Button click;
  10.     private Button clean;
  11.     private EditText input;
  12.     private TextView result;
  13.     @Override
  14.     protected void onCreate(Bundle savedInstanceState) {
  15.         super.onCreate(savedInstanceState);
  16.         setContentView(R.layout.activity_main);
  17.         click = (Button) findViewById(R.id.button2);
  18.         clean = (Button) findViewById(R.id.button1);
  19.         input = (EditText) findViewById(R.id.editText);
  20.         result = (TextView) findViewById(R.id.textView3);

  21.         click.setOnClickListener(new View.OnClickListener() {
  22.             @Override
  23.             public void onClick(View v) {
  24.                 double r = input.getText(). * 3.3058;
  25.                 result.setText("面積為: " + r + "平方公尺");
  26.             }
  27.         });

  28.         clean.setOnClickListener(new View.OnClickListener() {
  29.             @Override
  30.             public void onClick(View v) {
  31.                 input.setText("");
  32.                 result.setText("");
  33.             }
  34.         });
  35.     }

  36. }

  37. }
複製代碼

TOP

  1. <resources>
  2.     <string name="app_name">土地面積換算</string>
  3.     <string name="title">1 坪 = 3.3058 平方公尺</string>
  4.     <string name="tv">輸入坪數</string>
  5.     <string name="btn1">清除</string>
  6.     <string name="btn2">換算</string>
  7. </resources>
複製代碼
  1. [code]<?xml version="1.0" encoding="utf-8"?>
  2. <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
  3.     xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent"
  4.     android:layout_height="match_parent" android:paddingLeft="@dimen/activity_horizontal_margin"
  5.     android:paddingRight="@dimen/activity_horizontal_margin"
  6.     android:paddingTop="@dimen/activity_vertical_margin"
  7.     android:paddingBottom="@dimen/activity_vertical_margin" tools:context=".MainActivity"
  8.     android:orientation="vertical"
  9.     android:weightSum="1">

  10.     <TextView
  11.         android:layout_width="match_parent"
  12.         android:layout_height="80dp"
  13.         android:text="@string/title"
  14.         android:id="@+id/textView"
  15.         android:textSize="22sp"
  16.         android:textColor="#000000"
  17.         android:gravity="center" />

  18.     <TextView
  19.         android:layout_width="wrap_content"
  20.         android:layout_height="wrap_content"
  21.         android:text="@string/tv"
  22.         android:id="@+id/textView2"
  23.         android:textSize="22sp"
  24.         android:textColor="#000000" />

  25.     <EditText
  26.         android:layout_width="match_parent"
  27.         android:layout_height="wrap_content"
  28.         android:id="@+id/editText"
  29.         android:textSize="22sp" />

  30.     <TextView
  31.         android:layout_width="match_parent"
  32.         android:layout_height="80dp"
  33.         android:id="@+id/textView3"
  34.         android:layout_gravity="center_horizontal"
  35.         android:textSize="22sp"
  36.         android:gravity="center_vertical"
  37.         android:layout_weight="0.08" />

  38.     <LinearLayout
  39.         android:orientation="horizontal"
  40.         android:layout_width="match_parent"
  41.         android:layout_height="wrap_content"
  42.         android:layout_gravity="center_horizontal"
  43.         android:gravity="right">

  44.         <Button
  45.             android:layout_width="wrap_content"
  46.             android:layout_height="wrap_content"
  47.             android:text="@string/btn1"
  48.             android:id="@+id/button"
  49.             android:textSize="18sp" />

  50.         <Button
  51.             android:layout_width="wrap_content"
  52.             android:layout_height="wrap_content"
  53.             android:text="@string/btn2"
  54.             android:id="@+id/button2"
  55.             android:textSize="18sp" />
  56.     </LinearLayout>

  57. </LinearLayout>
複製代碼
[/code]

TOP

  1. <resources>
  2.         <string name="app_name">土地面積換算</string>
  3.         <string name="title">1 坪 = 3.3058 平方公尺</string>
  4.         <string name="tv">輸入坪數</string>
  5.         <string name="btn1">清除</string>
  6.         <string name="btn2">換算</string>
  7. </resources>
複製代碼
  1. <?xml version="1.0" encoding="utf-8"?>
  2. <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
  3.     xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent"
  4.     android:layout_height="match_parent" android:paddingLeft="@dimen/activity_horizontal_margin"
  5.     android:paddingRight="@dimen/activity_horizontal_margin"
  6.     android:paddingTop="@dimen/activity_vertical_margin"
  7.     android:paddingBottom="@dimen/activity_vertical_margin" tools:context=".MainActivity"
  8.     android:orientation="vertical"
  9.     android:weightSum="1">

  10.     <TextView
  11.         android:layout_width="match_parent"
  12.         android:layout_height="80dp"
  13.         android:text="@string/title"
  14.         android:id="@+id/textView"
  15.         android:textSize="22sp"
  16.         android:textColor="#000000"
  17.         android:gravity="center" />

  18.     <TextView
  19.         android:layout_width="wrap_content"
  20.         android:layout_height="wrap_content"
  21.         android:text="@string/tv"
  22.         android:id="@+id/textView2"
  23.         android:textSize="22sp"
  24.         android:textColor="#000000" />

  25.     <EditText
  26.         android:layout_width="match_parent"
  27.         android:layout_height="wrap_content"
  28.         android:id="@+id/editText"
  29.         android:textSize="22sp" />

  30.     <TextView
  31.         android:layout_width="match_parent"
  32.         android:layout_height="80dp"
  33.         android:id="@+id/textView3"
  34.         android:layout_gravity="center_horizontal"
  35.         android:textSize="22sp"
  36.         android:gravity="center_vertical"
  37.         android:layout_weight="0.08" />

  38.     <LinearLayout
  39.         android:orientation="horizontal"
  40.         android:layout_width="match_parent"
  41.         android:layout_height="wrap_content"
  42.         android:layout_gravity="center_horizontal"
  43.         android:gravity="right">

  44.         <Button
  45.             android:layout_width="wrap_content"
  46.             android:layout_height="wrap_content"
  47.             android:text="@string/btn1"
  48.             android:id="@+id/button"
  49.             android:textSize="18sp" />

  50.         <Button
  51.             android:layout_width="wrap_content"
  52.             android:layout_height="wrap_content"
  53.             android:text="@string/btn2"
  54.             android:id="@+id/button2"
  55.             android:textSize="18sp" />
  56.     </LinearLayout>

  57. </LinearLayout>
複製代碼
一年不見,如隔四季

TOP

  1. <?xml version="1.0" encoding="utf-8"?>
  2. <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
  3.     xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent"
  4.     android:layout_height="match_parent" android:paddingLeft="@dimen/activity_horizontal_margin"
  5.     android:paddingRight="@dimen/activity_horizontal_margin"
  6.     android:paddingTop="@dimen/activity_vertical_margin"
  7.     android:paddingBottom="@dimen/activity_vertical_margin" tools:context=".MainActivity"
  8.     android:orientation="vertical"
  9.     android:weightSum="1">

  10.     <TextView
  11.         android:layout_width="match_parent"
  12.         android:layout_height="80dp"
  13.         android:text="@string/title"
  14.         android:id="@+id/textView"
  15.         android:textSize="22sp"
  16.         android:textColor="#000000"
  17.         android:gravity="center" />

  18.     <TextView
  19.         android:layout_width="wrap_content"
  20.         android:layout_height="wrap_content"
  21.         android:text="@string/tv"
  22.         android:id="@+id/textView2"
  23.         android:textSize="22sp"
  24.         android:textColor="#000000" />

  25.     <EditText
  26.         android:layout_width="match_parent"
  27.         android:layout_height="wrap_content"
  28.         android:id="@+id/editText"
  29.         android:textSize="22sp" />

  30.     <TextView
  31.         android:layout_width="match_parent"
  32.         android:layout_height="80dp"
  33.         android:id="@+id/textView3"
  34.         android:layout_gravity="center_horizontal"
  35.         android:textSize="22sp"
  36.         android:gravity="center_vertical"
  37.         android:layout_weight="0.08" />

  38.     <LinearLayout
  39.         android:orientation="horizontal"
  40.         android:layout_width="match_parent"
  41.         android:layout_height="wrap_content"
  42.         android:layout_gravity="center_horizontal"
  43.         android:gravity="right">

  44.         <Button
  45.             android:layout_width="wrap_content"
  46.             android:layout_height="wrap_content"
  47.             android:text="@string/btn1"
  48.             android:id="@+id/button"
  49.             android:textSize="18sp" />

  50.         <Button
  51.             android:layout_width="wrap_content"
  52.             android:layout_height="wrap_content"
  53.             android:text="@string/btn2"
  54.             android:id="@+id/button2"
  55.             android:textSize="18sp" />
  56.     </LinearLayout>

  57. </LinearLayout>
複製代碼
七日不見 如隔一周

TOP

返回列表