Android的TextureView

来源:互联网 发布:蓝天cpu超频软件 编辑:程序博客网 时间:2024/04/29 08:25

代码如下

<?xml version="1.0" encoding="utf-8"?><GridLayout xmlns:android="http://schemas.android.com/apk/res/android"    android:layout_width="match_parent"    android:layout_height="match_parent"    android:columnCount="4"    android:rowCount="6"     android:id="@+id/root"  >    <TextureView         android:layout_width="match_parent"        android:layout_height="wrap_content"        android:layout_columnSpan="4"        android:layout_gravity="right"        android:layout_marginLeft="4px"        android:layout_marginRight="4px"        android:background="#eee"        android:padding="5px"        android:text="0"        android:textColor="#000"        android:textSize="50sp"         /> <Button        android:layout_width="match_parent"        android:layout_height="wrap_content"        android:layout_columnSpan="4"        android:text="清除"        />       </GridLayout>

package com.example.testo4;import com.example.test04.R;import android.os.Bundle;import android.app.Activity;import android.view.Gravity;import android.view.Menu;import android.widget.Button;import android.widget.GridLayout;public class MainActivity extends Activity {GridLayout gridLayout;// 定义16个按钮的文本String[] chars = new String[]{"7" , "8" , "9" , "÷","4" , "5" , "6" , "×","1" , "2" , "3" , "-","." , "0" , "=" , "+"};@Overrideprotected void onCreate(Bundle savedInstanceState) {super.onCreate(savedInstanceState);setContentView(R.layout.activity_main);gridLayout = (GridLayout)findViewById(R.id.root);for(int i = 0 ; i < chars.length ; i++){Button bn = new Button(this);bn.setText(chars[i]);// 设置该按钮的字体大小bn.setTextSize(40);// 指定该组件所在的行GridLayout.Spec rowSpec = GridLayout.spec(i / 4 + 2);// 指定该组件所在列GridLayout.Spec columnSpec = GridLayout.spec(i % 4);GridLayout.LayoutParams params = new GridLayout.LayoutParams(rowSpec , columnSpec);// 指定该组件占满父容器params.setGravity(Gravity.FILL);gridLayout.addView(bn , params);}}@Overridepublic 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;}}


1 0