I am trying to set the width and height of a view in code to show an ad for a free app I am working on. All of the UI is done in XML with the exception of this ad. Here is t
check it in mdpi device.. If the ad displays correctly, the error should be in "px" to "dip" conversion..
You can use something like code below, if you need to affect only specific value, and not touch others:
view.getLayoutParams().width = newWidth;
hsThumbList.setLayoutParams(new LayoutParams(100, 400));
in code add below line:
spin27.setLayoutParams(new LinearLayout.LayoutParams(200, 120));
The first parameter to LayoutParams is the width and the second is the height. So if you want the width to be FILL_PARENT, but the width to be, say, 20px, then use something new LayoutParams(FILL_PARENT, 20). Of course you should never use actual pixels in your code; you'll need to conver that to density-independent pixels, but you get the idea. Also, you need to make sure your parent LinearLayout has the right width and height that you're looking for. Seems to be you want the LinearLayout to fill the parent width-wise and then have the adview fill that linearlayout witdh-wise as well, so you probably need to specify android:layout_width:"fill_parent" and android:layout_height:"wrap_content" in your linear layout's xml.
yourView.setLayoutParams(new LinearLayout.LayoutParams(width, height));