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.
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