Android动态单行布局
我正在尝试创建一个动态布局。我的布局是由JSON提供的。我需要做的是在一行中放置一个按钮和一个编辑文本字段。编辑文本字段应始终填充屏幕真实状态,按钮应仅为其文本宽度大小。按钮可以放置在编辑文本字段之前或之后 代码方面,我正在尝试以下内容:Android动态单行布局,android,json,android-layout,Android,Json,Android Layout,我正在尝试创建一个动态布局。我的布局是由JSON提供的。我需要做的是在一行中放置一个按钮和一个编辑文本字段。编辑文本字段应始终填充屏幕真实状态,按钮应仅为其文本宽度大小。按钮可以放置在编辑文本字段之前或之后 代码方面,我正在尝试以下内容: for (int i = 0; i < jsonDataValue.size(); i++) { System.out.println(jsonDataValue.get(i)); if
for (int i = 0; i < jsonDataValue.size(); i++) {
System.out.println(jsonDataValue.get(i));
if (jsonDataViewType.get(i).toString().equals("editBox")) {
EditText editText = new EditText(context);
editText.setText(jsonDataValue.get(i));
editText.setWidth(LayoutParams.MATCH_PARENT);
editText.setHeight(LayoutParams.WRAP_CONTENT);
System.out.println("width: " + LayoutParams.MATCH_PARENT);
System.out.println("hight: " + editText.getHeight());
linearLayout.addView(editText);
System.out.println(linearLayout.getOrientation());
}
else if(jsonDataViewType.get(i).toString().equals("button")) {
Button button = new Button(context);
button.setText(jsonDataValue.get(i));
// button.setWidth(LayoutParams.WRAP_CONTENT);
linearLayout.addView(button);
}
}
for(int i=0;i
我得到的信息如下:
请尝试以下更新:
if (jsonDataViewType.get(i).toString().equals("editBox")) {
EditText editText = new EditText(context);
editText.setText(jsonDataValue.get(i));
LinearLayout.LayoutParams params = new LinearLayout.LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.WRAP_CONTENT);
params.weight = 1.0f;
editText.setLayoutParams(params);
}
嘿,我试过这个。但它不起作用。我无法更新/编辑我的问题。所以我不知道如何发布屏幕截图。你能回复吗?或者共享您的屏幕以供使用,只需交换LayoutParams.MATCH_父项和LayoutParams.WRAP_内容,因为构造函数定义为LinearLayout.LayoutParams(int-width,int-height)。我也从我的回答更新谢谢你的帮助。到目前为止似乎是这样。我正在尝试在已经添加的两个按钮上添加另一个按钮。但它在同一排。如何移动下面的测试按钮。