android


Set a Margin between two buttons programmatically from a linearlayout


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);

Related Links

Caused by: java.lang.ClassCastException
where to put checking edittext syntax?
Disadvantage of using sqlite? [closed]
Android OpenGL ES 2, Drawing squares
getting checked item from listview connected with override base adapter android
how to call webservice with https url in android
How to authenticate a user to a remote server in Android?
Click Event Coordinates on a WebView
Manifest error in Android
ActionBarSherlock Back button color change ?
How to create your own Magento mobile application for android and iphone [closed]
Why ProgressDialog is not always turning in my android application?
Android mergeAdapter ListView + HorizontalScrollView
Android Pause Before Loading Page
Can you drag-and-drop a TextView when it is in a child of a TableLayout?
possible to launch android app via NFC with passing parameters

Categories

HOME
windows
sonarqube
search
design-patterns
delphi-7
forms
wakanda
jmx
apiblueprint
jsf-2.2
graphics
ms-access-2016
rds
character
okhttp
openstreetmap
drop-down-menu
google-chrome-app
mod-security
onedrive-api
plink
scrolltop
heat
mongodb-csharp
symfony-2.8
android-7.0-nougat
swagger-2.0
apache2.4
asp.net-core-webapi
lilypond
pimcore
roundup
fractions
genexus-sd
wcag
carrierwave
jmockit
hreflang
keras-layer
openwhisk
reactjs.net
swagger-php
playframework-2.1
c9.io
magento-1.9.3
print-css
placeholder
apache-spark-dataset
strftime
double-click
cnc
fclose
convex-optimization
lightning
zenhub
git-flow
skin
janus
lsyncd
redbeard-ios
dimension
appscale
clipboard.js
tracker-enabled-dbcontext
bizagi
html-to-pdf
dynamics-nav-2016
toran-proxy
tfs-workitem
grgit
vigenere
include-guards
doctype
linked-tables
alloy-ui
nsurlsessiondatatask
osc
diff3
infosphere-spl
formview
universal-image-loader
strawberry-perl
gii
build-script
codeplex
square-bracket
ora-06550
mbunit
route-provider
actiondispatch
android-icons
composite-component
stacky
jquery-blockui
qtconcurrent
garbage
mapping-by-code
azman
usertype
fitbounds
stress
entity-attribute-value
exponentiation
mbeans
quotation-marks
cloudfiles
squishit
isapi-extension
zen
duplex
filesystemobject
firefox-3
movieplayer
online-storage

Resources

Database Users
RDBMS discuss
Database Dev&Adm
javascript
java
csharp
php
android
javascript
java
csharp
php
python
android
jquery
ruby
ios
html
Mobile App
Mobile App
Mobile App