如何动态创建带有textview和图像按钮的线性布局

时间:2014-03-19 21:54:33

标签: android

我想创建一个线性布局,其中包含文本视图和图像按钮。我想动态创建它。

1 个答案:

答案 0 :(得分:1)

LinearLayout layoutSection = new LinearLayout(getActivity());
LinearLayout.LayoutParams params = new LinearLayout.LayoutParams(
                            LinearLayout.LayoutParams.WRAP_CONTENT, LinearLayout.LayoutParams.MATCH_PARENT);
params.gravity = Gravity.CENTER;
params.setMargins(5,5,5,5);
imageView.setImageResource(R.drawable.image);
imageView.setLayoutParams(params);
TextView textView = newTextView(getActivity());
TextView.setText(("Enter text here");
layoutSection.addView(textView);
layoutSection.addView(imageView);