xml:
<FrameLayout 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:background="#0099cc" tools:context=".FullscreenActivity" >
<HorizontalScrollView android:background="#0099cc" android:layout_width="fill_parent" android:layout_height="fill_parent" > <LinearLayout android:layout_width="wrap_content" android:layout_height="fill_parent">
<EditText android:id="@+id/editNum1" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_gravity="center_vertical" android:inputType="number" android:text="0.0" />
<TextView android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_gravity="center_vertical" android:text="+" />
<EditText android:id="@+id/editNum2" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_gravity="center_vertical" android:inputType="number" android:text="0.0" />
<Button android:id="@+id/btEqualTo" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_gravity="center_vertical" android:text="等于" />
<TextView android:id="@+id/txtResult" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_gravity="center_vertical" android:text="0.0" />
</LinearLayout> </HorizontalScrollView>
</FrameLayout>
java:
package testPackage.example.testapp;
import testPackage.example.testapp.util.SystemUiHider;
import android.app.Activity;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.TextView;
/**
* An example full-screen activity that shows and hides the system UI (i.e.
* status bar and navigation/system bar) with user interaction.
*
* @see SystemUiHider
*/
public class FullscreenActivity extends Activity {
private EditText etNum1;
private EditText etNum2;
private TextView tvResult;
private Button btEqualTo;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_fullscreen);
//获取界面对象
etNum1=(EditText)findViewById(R.id.editNum1);
etNum2=(EditText)findViewById(R.id.editNum2);
tvResult=(TextView)findViewById(R.id.txtResult);
btEqualTo=(Button)findViewById(R.id.btEqualTo);
//添加 click
btEqualTo.setOnClickListener(btEqualTo_Click());
}
//等于事件
private View.OnClickListener btEqualTo_Click()
{
return new View.OnClickListener() {
@Override
public void onClick(View arg0) {
double num1= Double.parseDouble(etNum1.getText().toString());
double num2= Double.parseDouble(etNum2.getText().toString());
double result=num1+num2;
String value = String.valueOf(result);
tvResult.setText(value);
}
};
}
}