1

I need to put a view (a image for example) in a custom point of the interface. Are there a method to put a view in a exact pixel / virtual pixel (dp) - zone of the screen?

I need that the view is displayed above the other views.

I think to obligatory put a RelativeLayout and inside it all the layouts of the app and then put the view relative to this layout but i need a method more transparent to the future developers be able use it

EDIT:

I forget to say that i need to put the view programmatically and in the run time. I create the interface, make things in my app and then put a image in a concrete zone of the view above the others views for example in the half of the screen or in the top or in the 20% of the screen or ...

Aracem
  • 7,227
  • 4
  • 35
  • 72

3 Answers3

2

You can set margins for layouts and padding for views inside them, and you can specify position relative to edges, or to other views, there. Also you can specify fixed position for layouts by replacing (match_parent/fill_parent or wrap_content) with actual size( Note that you should specify all dimensions in dp or dip) For instance you have a linear layout and you want an image view to be 20 dp to the right of the left margin you can try something like this:

<LinearLayout
     android:layout_width="match_parent"
     android:layout_height="wrap_content"
     android::layout_marginLeft="20dp">
   <!-- Nest your views here and if you want you can set padding for them

</LinearLayout>

If you want your views to be on a certain part of the screen, like top of the screen/ bottom of the screen etc, you can nest all of them inside a RelativeLayout. This is a nice way to do it, and it will remove any confusion.

Good luck, Arkde

Aurelian Cotuna
  • 3,076
  • 3
  • 29
  • 49
  • Hi Arkde, i forget to say that i need to put the view programmaticall and after the interface is built. A perfect example is for example put a view similar to a ads of google admob ok? The program starts and then call to admob and admob put the ad. The problem is that i dont have any view in my xml and i need to put the new view in a custom place like "in the 20% screen from" the top or "in the half of the screen" or perhaps in the bottom or ... How you say, the relativelayout its a posibillity but if we found a method that is more transparent to future developers – Aracem Nov 17 '11 at 15:32
  • 1
    I still think that Relative Layout remains the best practice to go, since you can handle handle screen rotation pretty easy and without any other complication. You can set relative layout parameters programmatically or inflate them to speed up your up (compiled code from xml is executed directly, and it is not interpreted ), and you can do the same for nested views :) – Aurelian Cotuna Nov 17 '11 at 15:42
1

What about a FrameLayout as in the example I posted here?

Community
  • 1
  • 1
Narcís Calvet
  • 7,304
  • 5
  • 27
  • 47
  • Gracias Narcís, Thank you Narcís, i will mix your answer and Arkde's answer to solve my problem – Aracem Nov 17 '11 at 17:09
0

You can use AbsoluteLayout, although it's deprecated.

Patrick
  • 3,578
  • 5
  • 31
  • 53