android


Layout propertices programmatically


I have relativelayout as container, there i have set text and image, next i addView() this relativelayout twice to one linear layout, everything is fine but i cant separate the two relativelayouts they are alWays stick one to another, here is the code:
LinearLayout
layout = new LinearLayout(context);
LinearLayout.LayoutParams ll = new LinearLayout.LayoutParams(
LinearLayout.LayoutParams.MATCH_PARENT,
LinearLayout.LayoutParams.MATCH_PARENT);
ll.setMargins(5, 5, 5, 5);
layout.setOrientation(LinearLayout.HORIZONTAL);
layout.setPadding(5, 5, 5, 5);
layout.setLayoutParams(ll);
layout.setId(i);
layout.addView(m1.box);
layout.addView(m2.box);
where m1 and m2 are:
RelativeLayout:
box = new RelativeLayout(context);
RelativeLayout.LayoutParams rl = new RelativeLayout.LayoutParams(
RelativeLayout.LayoutParams.MATCH_PARENT,
RelativeLayout.LayoutParams.MATCH_PARENT);
rl.setMargins(5, 5, 5, 5);
rl.width = 125;
rl.height = 125;
box.setId(i);
box.setPadding(5, 5, 5, 5);
box.setBackgroundColor(color1);
box.setLayoutParams(rl);
//add some text and image
How to separate m1 from m2? Now they look like OO i need to add space O_O.
First, this doesn't work because the parent layout is a LinearLayout, and the LayoutParams you defined are of RelativeLayout. the LayoutParams should match the type of the parent and not the child, because they tell the parent how and where to place it's children.
Second, use addView(View v, LayoutParams lp) instead of addView(View v) to prevent this kind of mistakes.

Related Links

Android animation to rotate a image around its centre point
It is possible to run Robospice listener in non UI thread?
How to write a switch statement inside a method
Android - Copy files from assets to /data/data folder
Synchronize SQLite database and Dropbox datastore
WebView from Unity3d Android is not shown
Creating custom InfoWindowBox for each Marker
How to add shift key in Android custom keyboard?
What is the map used in navigation or object-tracking applications in Android?
Errors at showing a datepicker and timepicker
Browser sending “Dalvik” as user agent
Is it possible to create multiple AsyncTask at same time?
How to save image extracted from com.android.contacts, Android?
Android: new random sum after each click?
Detect Lock Screen Incorrect Password by user in Android
GraphUser object returns null “getUserName” while fetching friends from facebook in Android

Categories

HOME
uml
notepad++
httparty
kentico
css3
datastore
mstest
jelastic
saml-2.0
devise
carousel
nsbundle
alsa
permissions
web-hosting
discrete-mathematics
sendgrid-api-v3
siddhi
renjin
job-scheduling
symfony-console
bourbon
imageresizer
object-storage
scriptella
asymptotic-complexity
quantlib
mql
scrollview
panoramas
left-join
dumpbin
twos-complement
dynamic-jasper
reactjs.net
sql-delete
modernizr
verifiable-c
opensmpp
c9.io
visa
levenshtein-distance
datacachefactory
naming
monkey-testing
yii2-api
reportservice2010
fclose
trojan
static-cast
wpas
subnet
backbone-collections
excel-dna
avx
cd-burning
materialized-path-pattern
file-uri
watch-os-2
drawstring
tooleap
jclouds
clipboard.js
android-wake-lock
mediametadataretriever
riot
query-by-example
r-package
pypiserver
slash
rdflib
nsurlsessiondatatask
dot.js
browserify-shim
sonarqube-5.0
webfinger
wcm
mintty
maven-scm
amslidemenu
qscrollarea
git-repo
multitasking
high-resolution
gd-graph
http-patch
mysql-error-1044
kendo-dataviz
sqlclr
fragmenttransaction
cakephp-1.2
iboutlet
subgraph
mapping-by-code
koken
kqueue
isa-swizzling
infobright
procedures
jqote
undefined-index
updatesourcetrigger
feasibility
windows-identity
fdf
unmanagedresources

Resources

Encrypt Message