我想将引力设置在我的布局右侧,但它不能正常工作: (以下代码在循环内)
LinearLayout lin = new LinearLayout(getActivity());
LayoutParams lin_parms = new LayoutParams(LayoutParams.FILL_PARENT,LayoutParams.WRAP_CONTENT);
lin_parms.gravity = Gravity.RIGHT;
lin.setLayoutParams(lin_parms);
lin.setGravity(Gravity.RIGHT);
LayoutParams txt_parms = new LayoutParams(LayoutParams.FILL_PARENT,LayoutParams.WRAP_CONTENT);
txt_parms.gravity = Gravity.RIGHT;
TextView txt_view = new TextView(getActivity());
txt_view.setLayoutParams(txt_parms);
txt_view.setTypeface(font);
txt_view.setText("hello");
lin.addView(txt_view);
lay_lin_list_tractions.addView(lin);
答案 0 :(得分:2)
将TextView
参数设为WRAP_CONTENT
LayoutParams txt_parms = new LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT);