計算機介面,計算機介面設計

來源:互聯網
上載者:User

計算機介面,計算機介面設計

 

Demo2\jisuanqi\src\main\res\layout\activity_main.xml

 1 <GridLayout xmlns:android="http://schemas.android.com/apk/res/android" 2     xmlns:tools="http://schemas.android.com/tools" 3     android:layout_width="match_parent" 4     android:layout_height="match_parent" 5     tools:context=".MainActivity" 6     android:id="@+id/root" 7     android:rowCount="6" 8     android:columnCount="4"> 9     <!--定義一個橫跨4列的文字框-->10     <TextView11         android:layout_width="match_parent"12         android:layout_height="wrap_content"13         android:layout_columnSpan="4"14         android:textSize="50sp"15         android:layout_marginLeft="2dp"16         android:layout_marginRight="2dp"17         android:padding="3dp"18         android:layout_gravity="right"19         android:background="#eee"20         android:textColor="#000"21         android:text="0"/>22     <!--定義一個橫跨4列的按鈕-->23     <Button24         android:layout_width="match_parent"25         android:layout_height="wrap_content"26         android:layout_columnSpan="4"27         android:text="清除"/>28 29 30 </GridLayout>

 

Demo2\jisuanqi\src\main\java\com\ly\jisuanqi\MainActivity.java

 1 import android.app.Activity; 2 import android.os.Bundle; 3 import android.view.Gravity; 4 import android.widget.Button; 5 import android.widget.GridLayout; 6  7 public class MainActivity extends Activity { 8     private GridLayout gridLayout; 9     //定義16個按鈕的文本10     private String[] chars=new String[]{11             "7","8","9","/",12             "4","5","6","*",13             "1","2","3","-",14             ".","0","=","+",15     };16     private Button bn;17     @Override18     protected void onCreate(Bundle savedInstanceState) {19         super.onCreate(savedInstanceState);20         setContentView(R.layout.activity_main);21         gridLayout = (GridLayout) findViewById(R.id.root);22         for (int i = 0; i < chars.length; i++) {23             bn =new Button(this);24             bn.setText(chars[i]);25             //設定該按鈕的字型大小大小26             bn.setTextSize(40);27             //設定按鈕四周的空白地區28             bn.setPadding(5,35,5,35);29             //指定該組件所在的行30             GridLayout.Spec rowSpec = GridLayout.spec(i/4+2);31             //指定該組件所在的列32             GridLayout.Spec columnSpec=GridLayout.spec(i%4);33             GridLayout.LayoutParams params = new GridLayout.LayoutParams(rowSpec,columnSpec);34             //指定該組件佔滿父容器35             params.setGravity(Gravity.FILL);36             gridLayout.addView(bn,params);37         }38     }39 40 41 }

 

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.