how to get the bottom of a layout in android? -


I am using a relative layout in Android, and keeping the scene low by adding a view to the bottom of the screen Compared to the actual bottom of the screen, where the user can not really see it

  view.setY (container.getBottom () - view.getHeight ()); Container.addView (see);   

The container is a relative layout I have also tried to use container.getHeight (), which gave me the same result, and all the other solutions I have received where the xml file Use, which does not work for me, because I need to add dynamically to a random position above the scene at the bottom of the screen, which means

 . Set Y (ContainerGetHight () - Normal.Random.exeflat () * 100- Rishykgethaigt ());   

This is the XML

  & lt; Relative layout xmlns: android = "http://schemas.android.com/apk/res/android" xmlns: tool = "http://schemas.android.com/tools" Android: layout_width = "match_parent" Android: layout_height = "Match_parent" Android: id = "@ + ID / layout" tool: Reference = "IL.Com ovalley.dashvsponypolice.app.MainActivity" & gt; & Lt; / RelativeLayout & gt;   

See more IM is trying to add:

  public class GameView ImageView {Expands Public GameView (RelativeLayout Container) {Super ( Container.getContext ()); M_container = container; Container.addView (this); }} Public Class Cop GameView {Expands Public Cop (Relative Layout Container) {Super (Container); M_isShooting = false; M_LoadingTime = 10; m_isLoading = False; M_xSpeed ​​= 1.5f; SetY (container.getHyight () - Common.random.nextFloat () * 100-getHeight () / * - getPaddingBottom () * /); Float x = (normal.random.exeflat () * m_container.getWidth ()); SetX (x); DrwableState = 0; Change direction (); }   

I have tested that on various versions of Android and the size of the screen and the same result found. So far, I found that the height of the only container was to subtract a arbitrary int, which looks fine on one device and is the best hope for others, I'm sure there is a better solution.


You just go to the bottom of the screen ALIGN_PARENT_BOTTOM and then apply a random padding?

  Relative layout. Layout Parameters Parameters = New Relative Layout. LayoutPam (Layout Paramah.MATPArment, Layout paragraph params.addRule (RelativeLayout.ALIGN_PARENT_BOTTOM); View.setPadding (0, 0, 0, Random Value); // Left, Top, Right, Bottom Container.Adview (see, Parameters) ;   

It is not good to compute with view.getHeight () This is working without anybody managing

Comments

Popular posts from this blog

Verilog Error: output or inout port "Q" must be connected to a structural net expression -

jasper reports - How to center align barcode using jasperreports and barcode4j -

c# - ASP.NET MVC - Attaching an entity of type 'MODELNAME' failed because another entity of the same type already has the same primary key value -