手写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 p...
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);
}
}
您可能感兴趣的文章:
本站(WWW.)站内文章除注明原创外,均为转载、整理或搜集自网络。欢迎任何形式的转载,转载请注明出处。