0

I've a big problem I'm trying to add an Imageview programmatically but I face a strange problem:

I've put in the XML just an empty Relative Layout matching the parent. Code wise I'm adding an imageview to the relative layout.

Everything works, the imageview is visible and sized correctly, but the problem is that the "0,0" position is weird. It seems that it has a Top Margin while instead the Left Margin is correctly 0. Also forcing the position to "0,0" with SetX/SetY results with this wierd top border:

Image:

enter image description here

Code:

base_layout = (RelativeLayout) findVieById(R.id.base_layout);

image_logo = New Imageview(this);
base_layout.AddView(image_logo);

image_logo.SetPadding(0,0,0,0);
image_logo.SetX(0);
image_logo.SetY(0);
image_logo.SetImageResource(R.drawable.generic_image);
image_logo.SetVisibility(View.VISIBLE);

I don't understand why..the activity in the manifest has its usual Theme.NoTitleBar.Fullscreen flag.

Any help? It will be really appreciated!

user13400
  • 21
  • 4
  • To get a quick helpful answer (and to make your question more helpful), show us what you've done in code so we can understand what's going on. – Rudi Kershaw Jul 04 '14 at 08:22
  • 1
    Have you tried setting the `RelativeLayout` element's paddings to 0? – Rudi Kershaw Jul 04 '14 at 08:27
  • Hi, I've edited it the post. – user13400 Jul 04 '14 at 08:33
  • Hi Rudi, thank you for the quick reply. No even with padding 0, 0, 0, 0 it shows that border. I think is somethingh related to the titlebar but I don't understand...using xml it works perfectly. – user13400 Jul 04 '14 at 08:42
  • Are you sure that tiny gap at the top isn't just the bar where the battery life/wireless signal and notifications go? – Rudi Kershaw Jul 04 '14 at 09:01
  • Hi Rudy, thank you again. Since I've set Fullscreen and no titlebar I don't see any notification/battery/wifi bar the app is completely fullscreen. But yes it seems like that space is counted like busy...so even if I see the blue background of my RelativeLayout, position 0,0 of the screen seems to be Y-offsetted. Do you have any idea? help :(( – user13400 Jul 04 '14 at 09:05

1 Answers1

0

I put together an example using RelativeLayout.LayoutParams and tried it myself and everything appears to be working fine.

 base_layout = (RelativeLayout) findViewById(R.id.base_layout);        
 ImageView image_logo = new ImageView(this);
 RelativeLayout.LayoutParams lp = new RelativeLayout.LayoutParams(width, height);
 image_logo.setLayoutParams(lp);
 base_layout.addView(image_logo);

The above shows the below effect when run.

enter image description here

android:theme="@android:style/Theme.NoTitleBar.Fullscreen" was used in the manifest against this Activity.

Rudi Kershaw
  • 12,332
  • 7
  • 52
  • 77
  • Using the FULLSCREEN manifest flag actually hides the notification bar but I'm not sure the layout coordinates are affected too. Do you think adding the following will fix my problem? getWindow().addFlags(WindowManager.LayoutParams.FLAG_LAYOUT_IN_SCREEN); – user13400 Jul 04 '14 at 09:32