package com.example.helloworld01;//包名
import java.util.ArrayList;
import java.util.List;
import android.os.Bundle;
import android.app.Activity;
import android.graphics.Color;
import android.widget.ArrayAdapter;
import android.widget.Button;
import android.widget.LinearLayout;
import android.widget.ListView;
import android.widget.RelativeLayout;
import android.widget.RelativeLayout.LayoutParams;
public class MainActivity extends Activity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
// 定义线性布局
LinearLayout linearLayout = new LinearLayout(this);
linearLayout.setOrientation(LinearLayout.VERTICAL);
// 定义相对布局
RelativeLayout relativeLayout = new RelativeLayout(this);
relativeLayout.setBackgroundColor(Color.GRAY);
// 定义两个按钮
Button button1 = new Button(this);
button1.setText("按钮1");
Button button2 = new Button(this);
button2.setText("按钮2");
android代码中设置两个按钮之间位置
最新推荐文章于 2023-02-26 12:36:39 发布
![](https://img-home.csdnimg.cn/images/20240711042549.png)