Android教程網
  1. 首頁
  2. Android 技術
  3. Android 手機
  4. Android 系統教程
  5. Android 游戲
 Android教程網 >> Android技術 >> 關於Android編程 >> 手寫android布局示例

手寫android布局示例

編輯:關於Android編程

復制代碼 代碼如下:
package com.test;

import android.app.Activity;
import android.os.Bundle;
//import android.view.View;
import android.widget.Button;
import android.widget.LinearLayout;
//import android.widget.Toast;

public class Test_javaActivity extends Activity {

        @Override
        public void onCreate(Bundle savedInstanceState) {
                super.onCreate(savedInstanceState);

                LinearLayout layout = new LinearLayout(this);
                // layout.setOrientation(LinearLayout.VERTICAL);

                Button button = new Button(this);

                button.setText("Click Me");

                button.setLayoutParams(new LinearLayout.LayoutParams(
                                LinearLayout.LayoutParams.FILL_PARENT,
                                LinearLayout.LayoutParams.WRAP_CONTENT));

/**                button.setOnClickListener(new View.OnClickListener() {
                        @Override
                        public void onClick(View v) {
                                Toast.makeText(Test_javaActivity.this, "Button Clicked",
                                                Toast.LENGTH_LONG).show();
                        }
                });
*/
                layout.addView(button);
                setContentView(layout);
        }
}

  1. 上一頁:
  2. 下一頁:
熱門文章
閱讀排行版
Copyright © Android教程網 All Rights Reserved