从LinearLayout中设置两个按钮编程之间的保证金 [英] Set a Margin between two buttons programmatically from a linearlayout
本文介绍了从LinearLayout中设置两个按钮编程之间的保证金的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
如何设置的20dp按钮Regler公司和decommender编程之间的余量。
这是我的工作方式
的LinearLayout lytmain =新的LinearLayout(Mcontex);
lytmain.setOrientation(LinearLayout.VERTICAL);
的LinearLayout lytdate =新的LinearLayout(Mcontex);
的LinearLayout lytbutton =新的LinearLayout(Mcontex);
lytbutton.setBackgroundResource(R.color.black);
lytbutton.setBackgroundResource(R.color.black);
lytdate.setBackgroundResource(R.color.black);
lytmain.setBackgroundResource(R.color.black);
按钮btnset =新按钮(Mcontex);
按钮btncancel =新按钮(Mcontex);
btncancel.setShadowLayer(2,1,1,R.color.black);
btnset.setShadowLayer(2,1,1,R.color.black);
btnset.setBackgroundResource(R.drawable.black_button);
btncancel.setBackgroundResource(R.drawable.black_button);
btnset.setTextColor(Mcontex.getResources()的getColor(R.color.white));
btncancel.setTextColor(Mcontex.getResources()的getColor(R.color.white));
btncancel.setTextSize(15);
btnset.setTextSize(15);
btnset.setText(Regler公司);
btncancel.setText(Décommander);
btnset.setGravity(Gravity.CENTER);
btncancel.setGravity(Gravity.CENTER);
最后WheelView月=新WheelView(Mcontex);
最后WheelView年=新WheelView(Mcontex);
最后WheelView天=新WheelView(Mcontex);
lytdate.addView(天,新的LayoutParams(
android.view.ViewGroup.LayoutParams.WRAP_CONTENT,
android.view.ViewGroup.LayoutParams.WRAP_CONTENT,1.2F));
lytdate.addView(月,新的LayoutParams(
android.view.ViewGroup.LayoutParams.WRAP_CONTENT,
android.view.ViewGroup.LayoutParams.WRAP_CONTENT,0.8f));
lytdate.addView(一年,新的LayoutParams(
android.view.ViewGroup.LayoutParams.WRAP_CONTENT,
android.view.ViewGroup.LayoutParams.WRAP_CONTENT,1F));
requestWindowFeature(Window.FEATURE_NO_TITLE);
lytbutton.addView(btnset,新的LayoutParams(
android.view.ViewGroup.LayoutParams.WRAP_CONTENT,
android.view.ViewGroup.LayoutParams.WRAP_CONTENT,1.5F));
lytbutton.addView(btncancel,新的LayoutParams(
android.view.ViewGroup.LayoutParams.WRAP_CONTENT,
android.view.ViewGroup.LayoutParams.WRAP_CONTENT,1.5F));
lytbutton.setPadding(5,5,5,5);
lytmain.addView(lytdate);
lytmain.addView(lytbutton);
的setContentView(lytmain);
getWindow()。setLayout的(LayoutParams.FILL_PARENT,
LayoutParams.WRAP_CONTENT);
解决方案
使用LinearLayout.LayoutParams
<一个href="http://developer.android.com/reference/android/widget/LinearLayout.LayoutParams.html">http://developer.android.com/reference/android/widget/LinearLayout.LayoutParams.html
您可以setMargins到的LayoutParams,然后setLayoutParams你的看法。
LinearLayout.LayoutParams PARAMS =新LinearLayout.LayoutParams(
LayoutParams.WRAP_CONTENT,LayoutParams.WRAP_CONTENT);
params.setMargins(0,2,0,0);
button.setLayoutParams(PARAMS);
How can i set a margin of 20dp between the button "regler" and "decommender" programmatically.
Here is my workings
LinearLayout lytmain = new LinearLayout(Mcontex);
lytmain.setOrientation(LinearLayout.VERTICAL);
LinearLayout lytdate = new LinearLayout(Mcontex);
LinearLayout lytbutton = new LinearLayout(Mcontex);
lytbutton.setBackgroundResource(R.color.black);
lytbutton.setBackgroundResource(R.color.black);
lytdate.setBackgroundResource(R.color.black);
lytmain.setBackgroundResource(R.color.black);
Button btnset = new Button(Mcontex);
Button btncancel = new Button(Mcontex);
btncancel.setShadowLayer(2, 1, 1, R.color.black);
btnset.setShadowLayer(2, 1, 1, R.color.black);
btnset.setBackgroundResource(R.drawable.black_button);
btncancel.setBackgroundResource(R.drawable.black_button);
btnset.setTextColor(Mcontex.getResources().getColor(R.color.white));
btncancel.setTextColor(Mcontex.getResources().getColor(R.color.white));
btncancel.setTextSize(15);
btnset.setTextSize(15);
btnset.setText("Régler");
btncancel.setText("Décommander");
btnset.setGravity(Gravity.CENTER);
btncancel.setGravity(Gravity.CENTER);
final WheelView month = new WheelView(Mcontex);
final WheelView year = new WheelView(Mcontex);
final WheelView day = new WheelView(Mcontex);
lytdate.addView(day, new LayoutParams(
android.view.ViewGroup.LayoutParams.WRAP_CONTENT,
android.view.ViewGroup.LayoutParams.WRAP_CONTENT, 1.2f));
lytdate.addView(month, new LayoutParams(
android.view.ViewGroup.LayoutParams.WRAP_CONTENT,
android.view.ViewGroup.LayoutParams.WRAP_CONTENT, 0.8f));
lytdate.addView(year, new LayoutParams(
android.view.ViewGroup.LayoutParams.WRAP_CONTENT,
android.view.ViewGroup.LayoutParams.WRAP_CONTENT, 1f));
requestWindowFeature(Window.FEATURE_NO_TITLE);
lytbutton.addView(btnset, new LayoutParams(
android.view.ViewGroup.LayoutParams.WRAP_CONTENT,
android.view.ViewGroup.LayoutParams.WRAP_CONTENT,1.5f));
lytbutton.addView(btncancel, new LayoutParams(
android.view.ViewGroup.LayoutParams.WRAP_CONTENT,
android.view.ViewGroup.LayoutParams.WRAP_CONTENT, 1.5f));
lytbutton.setPadding(5, 5, 5, 5);
lytmain.addView(lytdate);
lytmain.addView(lytbutton);
setContentView(lytmain);
getWindow().setLayout(LayoutParams.FILL_PARENT,
LayoutParams.WRAP_CONTENT);
解决方案
Use LinearLayout.LayoutParams
http://developer.android.com/reference/android/widget/LinearLayout.LayoutParams.html
You can setMargins to LayoutParams, then setLayoutParams to your view.
LinearLayout.LayoutParams params = new LinearLayout.LayoutParams(
LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT);
params.setMargins(0, 2, 0, 0);
button.setLayoutParams(params);
这篇关于从LinearLayout中设置两个按钮编程之间的保证金的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文