设置按钮的保证金编程 [英] Setting Button's margin programmatically
问题描述
我是新来的Android和停留在一个非常基本的疑难问题。我的工作在我需要在fling.On刷卡的生动形象我要补充dynamically.I正在增加使用AddContentView按钮按钮的应用程序()添加buttons.Everything工作正常,但我想设置的按钮dynamically.I读过的许多地方的位置,每个人都使用addView()来添加按钮并设置其positions.I已经尝试了本
I am new to android and stuck in a very basic problem.I am working on an application in which I need to swipe images on fling.On every image I have to add buttons dynamically.I am adding buttons using AddContentView() to add buttons.Everything is working fine but I want to set the position of buttons dynamically.I have read at many places,everyone is using addView() to add buttons and setting their positions.I have tried this
但它不是working.Can谁能告诉我如何设置按钮的使用addContentView边缘(位置)()。任何帮助将非常是AP preciated。
but it isn't working.Can anyone please tell me how to set the margins(position) of button using addContentView().Any help would highly be appreciated.
推荐答案
设置使用addView一个按钮利润率为我工作。一定要通过正确的LayoutParams反对,应该握住你的按钮的ViewGroup。
Setting a buttons margin using addView works for me. Be sure to pass the right LayoutParams object to the ViewGroup that should hold your button.
FrameLayout fl = new FrameLayout(context);
Button b = new Button(context);
FrameLayout.LayoutParams params = new FrameLayout.LayoutParams(width, height);
params.setMargins(top, left, bottom, right);
fl.addView(b,params);
应该工作。
这篇关于设置按钮的保证金编程的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!