嗨,我正在尝试将一个按钮加载到视图寻呼机中,并且我已将其加载,但它目前正在填充整个屏幕,我希望它将内容包装到其确切大小,然后将其放置在屏幕中间。我试图为按钮设置布局参数,但是当我运行应用程序时它仍然填充父级。有谁知道如何以编程方式设置按钮的布局和位置?
这是我到目前为止所尝试的
@Override
public Object instantiateItem(View collection, int position) {
RelativeLayout.LayoutParams rel_btn = new RelativeLayout.LayoutParams(
LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT);
rel_btn.addRule(RelativeLayout.CENTER_VERTICAL);
rel_btn.addRule(RelativeLayout.CENTER_HORIZONTAL);
rel_btn.height = 60;
rel_btn.width = 60;
Button tv = new Button(cxt);
tv.setLayoutParams(rel_btn);
tv.setText("League " + (position+1));
tv.setTextColor(Color.WHITE);
tv.setTextSize(30);
tv.setBackgroundDrawable(getResources().getDrawable(R.drawable.ls_level_eng1));
((ViewPager) collection).addView(tv,0);
return tv;
}