我需要在Android的Fragment中从右侧布局视图,但是,android没有像我想的那样布局子视图。 我尝试将TableLayout和ImageView添加到LINEARLAYOUT,ImageView的宽度是固定的,TableLayout的宽度是动态的。此外,ImageView需要位于右侧。 部分源代码:
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,Bundle savedInstanceState) {
Context c = getActivity().getApplicationContext();
LinearLayout l = new LinearLayout(c);
LayoutParams params = new LayoutParams(LayoutParams.MATCH_PARENT,
LayoutParams.MATCH_PARENT, 0);
params.gravity = Gravity.RIGHT;
l.setLayoutParams(params);
// l.setGravity(Gravity.RIGHT);
PankouAttachmentView pav = new PankouAttachmentView(c, null);
pav.setLayoutParams(params);
l.addView(pav);
ImageView iv = new ImageView(c);
iv.setClickable(true);
iv.setFocusable(true);
iv.setImageResource(R.drawable.testarrow);
iv.setMaxWidth(BUTTON_WIDTH);
iv.setLayoutParams(new LayoutParams(BUTTON_WIDTH,
LayoutParams.MATCH_PARENT));
l.addView(iv);
return l;
}
任何帮助将不胜感激.THX:)