【发布时间】:2014-11-20 08:25:06
【问题描述】:
我有一个 Android 应用,我正在尝试在代码中创建以下布局:
这是我目前的代码:
public class MyLayout extends LinearLayout {
private Context mContext;
public MyLayout(Context context) {
super(context);
mContext = context;
this.build();
}
private void build() {
LinearLayout parent = new LinearLayout(mContext);
parent.setLayoutParams(new LinearLayout.LayoutParams(LayoutParams.FILL_PARENT,
LayoutParams.FILL_PARENT));
GridView gridView = new GridView(this.mContext);
gridView.setNumColumns(2);
ViewGroup.LayoutParams params = new ViewGroup.MarginLayoutParams(
MarginLayoutParams.FILL_PARENT,
MarginLayoutParams.WRAP_CONTENT);
gridView.setLayoutParams(params);
parent.addView(gridView);
addView(parent);
}
}
如何添加 ImageView 使其停靠在 LinearLayout 的底部?
【问题讨论】:
-
为什么不用XML文件来实现布局?
-
我正在开发的应用程序在代码中构建此屏幕,但是我愿意使用 xml。我将如何在 XML 中做到这一点?
标签: android android-layout gridview imageview