java文本框布局_java – 如何设置编辑文本框的布局边距?

本文介绍了如何在Java的TableLayout中,为表格行内的多个EditText编辑文本框设置布局边距。通过实例展示了如何创建TableRow,设置背景颜色,并为每个EditText设置文本颜色、背景颜色和文本内容,最后将这些文本框添加到表格行中。
摘要由CSDN通过智能技术生成

在表格布局中我有一个tablerow,在该tablerow中我有6个编辑文本框,我想为这6个编辑文本框设置布局边距

TableLayout t1=(TableLayout)findViewById(R.id.table_layout01);

TableRow tr1=new TableRow(inventory.this);

tr1.setLayoutParams(new LayoutParams(LayoutParams.FILL_PARENT,LayoutParams.WRAP_CONTENT));

tr1.setBackgroundColor(Color.BLACK);

EditText ed6=new EditText(inventory.this);

//ed6.setLayoutParams(new LayoutParams(LayoutParams.WRAP_CONTENT,LayoutParams.WRAP_CONTENT));

/*ViewGroup.MarginLayoutParams editmargin=new ViewGroup.MarginLayoutParams(ViewGroup.MarginLayoutParams.FILL_PARENT,ViewGroup.MarginLayoutParams.WRAP_CONTENT);

editmargin.setMargins(leftMargin, rightMargin, topMargin, bottomMargin);*/

ed6.setTextColor(Color.BLACK);

ed6.setBackgroundColor(Color.WHITE);

ed6.setText("1");

tr1.addView(ed6);

EditText ed7=new EditText(inventory.this);

//ed7.setLayoutParams(new LayoutParams(LayoutParams.WRAP_CONTENT,LayoutParams.WRAP_CONTENT));

ed7.setTextColor(Color.BLACK);

ed7.setBackgroundColor(Color.WHITE);

ed7.setText("2");

tr1.addView(ed7);

EditText ed8=new EditText(inventory.this);

//ed8.setLayoutParams(new LayoutParams(LayoutParams.WRAP_CONTENT,LayoutParams.WRAP_CONTENT));

ed8.setTextColor(Color.BLACK);

ed8.setBackgroundColor(Color.WHITE);

ed8.setText("3");

tr1.addView(ed8);

EditText ed9=new EditText(inventory.this);

//ed9.setLayoutParams(new LayoutParams(LayoutParams.WRAP_CONTENT,LayoutParams.WRAP_CONTENT));

ed9.setTextColor(Color.BLACK);

ed9.setBackgroundColor(Color.WHITE);

ed9.setText("4");

tr1.addView(ed9);

EditText ed10=new EditText(inventory.this);

//ed10.setLayoutParams(new LayoutParams(LayoutParams.WRAP_CONTENT,LayoutParams.WRAP_CONTENT));

ed10.setTextColor(Color.BLACK);

ed10.setText("5");

ed10.setBackgroundColor(Color.WHITE);

tr1.addView(ed10);

EditText ed11=new EditText(inventory.this);

//ed11.setLayoutParams(new LayoutParams(LayoutParams.WRAP_CONTENT,LayoutParams.WRAP_CONTENT));

ed11.setTextColor(Color.BLACK);

ed11.setText("6");

ed11.setBackgroundColor(Color.WHITE);

tr1.addView(ed11);

t1.addView(tr1);

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
### 回答1: 很抱歉,Java是一种编程语言,不适合用于页面布局。通常前端开发使用HTML、CSS和JavaScript来实现页面布局。以下是一个简单的HTML页面布局示例: ```html <!DOCTYPE html> <html> <head> <title>页面布局示例</title> <style> /* CSS样式 */ body { font-family: Arial, sans-serif; margin: 0; padding: 0; } header { background-color: #333; color: #fff; padding: 20px; text-align: center; } nav { background-color: #f2f2f2; padding: 10px; } nav ul { list-style: none; margin: 0; padding: 0; } nav ul li { display: inline-block; margin-right: 10px; } nav ul li a { color: #333; text-decoration: none; padding: 5px 10px; } main { margin: 20px; } section { display: flex; flex-wrap: wrap; justify-content: space-between; } article { width: 30%; margin-bottom: 20px; background-color: #f2f2f2; padding: 10px; } footer { background-color: #ccc; color: #333; padding: 20px; text-align: center; } </style> </head> <body> <header> <h1>页面布局示例</h1> </header> <nav> <ul> <li><a href="#">首页</a></li> <li><a href="#">产品</a></li> <li><a href="#">服务</a></li> <li><a href="#">关于我们</a></li> <li><a href="#">联系我们</a></li> </ul> </nav> <main> <section> <article> <h2>文章标题</h2> <p>文章内容</p> </article> <article> <h2>文章标题</h2> <p>文章内容</p> </article> <article> <h2>文章标题</h2> <p>文章内容</p> </article> </section> </main> <footer> 版权所有 © 2021 </footer> </body> </html> ``` 这段代码定义了一个简单的页面布局,包括一个头部、导航栏、主要内容区域和页脚。可以通过修改CSS样式来实现不同的页面布局效果。 ### 回答2: 以下是一个简单的页面布局Java代码: ```java import javafx.application.Application; import javafx.geometry.Insets; import javafx.scene.Scene; import javafx.scene.control.Button; import javafx.scene.layout.GridPane; import javafx.stage.Stage; public class PageLayout extends Application { @Override public void start(Stage primaryStage) { // 创建一个网格布局 GridPane gridPane = new GridPane(); // 设置网格的内边距 gridPane.setPadding(new Insets(10)); // 设置网格中的元素之间的水平和垂直间距 gridPane.setHgap(10); gridPane.setVgap(10); // 创建按钮 Button button1 = new Button("按钮1"); Button button2 = new Button("按钮2"); Button button3 = new Button("按钮3"); // 将按钮添加到网格布局中 gridPane.add(button1, 0, 0); gridPane.add(button2, 1, 0); gridPane.add(button3, 0, 1, 2, 1); // 创建场景,并将网格布局添加到场景中 Scene scene = new Scene(gridPane, 300, 200); // 设置主舞台的标题和场景 primaryStage.setTitle("页面布局"); primaryStage.setScene(scene); // 显示主舞台 primaryStage.show(); } public static void main(String[] args) { // 启动JavaFX应用程序 launch(args); } } ``` 以上代码使用JavaFX创建一个简单的页面布局布局中使用了一个网格布局(GridPane),将按钮放置在不同的网格位置中。通过设置边距和间距,达到合适的页面布局效果。最后将网格布局添加到场景(Scene)中,并将场景设置为主舞台(Stage)的内容,显示在屏幕上。 ### 回答3: 以下是一个简单的页面布局Java代码示例: ```java import javax.swing.*; import java.awt.*; public class PageLayout extends JFrame { public PageLayout() { setTitle("页面布局示例"); setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); // 创建容器 Container container = getContentPane(); // 创建网格布局管理器 GridLayout gridLayout = new GridLayout(3, 2); container.setLayout(gridLayout); // 创建标签和文本框 JLabel nameLabel = new JLabel("姓名:"); JTextField nameField = new JTextField(); JLabel ageLabel = new JLabel("年龄:"); JTextField ageField = new JTextField(); JLabel cityLabel = new JLabel("城市:"); JTextField cityField = new JTextField(); // 将标签和文本框添加到容器中 container.add(nameLabel); container.add(nameField); container.add(ageLabel); container.add(ageField); container.add(cityLabel); container.add(cityField); // 设置窗口大小和显示 setSize(300, 200); setVisible(true); } public static void main(String[] args) { new PageLayout(); } } ``` 以上代码创建了一个页面布局Java窗口,使用了网格布局管理器将姓名、年龄和城市三个标签和文本框放置在窗口中。窗口大小为300x200,并设置为可见状态。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值