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

Cannot inactivate a subscription in Google Developer Console - the Active/Inactive switch is disabled
Left padding when set new data on BarChart View from MPAndroidChart library
How to achieve Pixel Launcher Swipe Up
getLineCount() on TextView in RecyclerView returning zero
android studio storing information?
android:src attrs for custom view
Location Provider Sometimes returns Sydney location points
Tab Title in tablayout+view pager Not showing in Android 5.0 and above after adding CoordinatorLayout
AccessibilityService onKeyEvents not getting fired in Moto phone
Glide not loading image without placeholder
Drawing a listview through ListItem.add returns always a position = 0
Text length limits using BigPictureStyle notifications
Dynamically change list in FragmentPagerAdapter in Fragment Android
How to handle an Action View Intent inside my own app
Linking Sketchup object to OpenGLES in Android application
Tabs having Fragment Showing Blank Screen after sdk update

Categories

HOME
oracle12c
gridview
api
character-encoding
fftw
oracle-apex-5
solver
requirements
error-handling
nuget
rom
alsa
interpolation
elasticsearch-5
openstreetmap
appcelerator-studio
mod-security
ipmitool
spring-social
endpoint
code-generation
frequency-distribution
googlebot
dpdk
angular-routing
epsilon
dapper-extensions
syntax-highlighting
bioinformatics
browser-sync
realm-mobile-platform
autodesk-designautomation
complex-numbers
turfjs
code-snippets
linkedhashmap
latitude-longitude
dm-script
apns-php
gdata
metaprogramming
css-position
spring-mvc-test
naming
angular-http
openal
proget
netbeans6.8
dbcontext
yii2-user
edit
headless
excel-dna
vibrate
rxtx
reachability
microstation
envi
spring-cloud-feign
xdoclet
kiosk
concept-insights
relativelayout
custom-errors
lazybones
dock
finalbuilder
sha512
jsvc
cryptographichashfunction
metatrader5
angular-carousel
build-script
android-framework
rfc5322
spring-3
solace-mq
http-patch
ie8-compatibility-mode
unit-of-work
route-provider
actiondispatch
twisted.web
qi4j
paginator
jdb
database-create
box2d-iphone
entity-attribute-value
saxparseexception
htdocs
ie-compatibility-mode
folding
filesystemobject
sun
google-wave
software-lifecycle
fdf
flvplayback
product-management
commercial-application

Resources

Mobile Apps Dev
Database Users
javascript
java
csharp
php
android
MS Developer
developer works
python
ios
c
html
jquery
RDBMS discuss
Cloud Virtualization
Database Dev&Adm
javascript
java
csharp
php
python
android
jquery
ruby
ios
html
Mobile App
Mobile App
Mobile App