亲宝软件园·资讯

展开

android布局 手写android布局示例

人气:0
想了解手写android布局示例的相关内容吗,在本文为您仔细讲解android布局的相关知识和一些Code实例,欢迎阅读和指正,我们先划重点: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);
        }
}

加载全部内容

相关教程
猜你喜欢
用户评论