Note that there are some explanatory texts on larger screens.

plurals
  1. POAndroid Position Custom Toast Above User's touch
    primarykey
    data
    text
    <p>I have created a custom background for a Toast message. I use the MotionEvent to grab the rawX and rawY then show the Toast where the user tapped. The only issue is that the top of the Toast appears below the users touch point and not above it. So basically if I knew the height of the Toast when I show it I could move it up the Y axis that much so it would be above the users tap x,y point. However, you can't get the height of the Toast before it is drawn. Else is there another way to achieve the right position with the Gravity parameters?</p> <pre><code> //Retrieve the layout inflator LayoutInflater inflater = (LayoutInflater) ctx.getSystemService(Context.LAYOUT_INFLATER_SERVICE); //Assign the custom layout to view //Parameter 1 - Custom layout XML //Parameter 2 - Custom layout ID present in linearlayout tag of XML View layout = inflater.inflate(R.layout.popup_toast, (ViewGroup) llayParent.findViewById(R.id.popToastLayoutRoot)); m_tv_what = (TextView)layout.findViewById(R.id.ptextWhat); m_tv_priority = (TextView)layout.findViewById(R.id.ptextPrior); m_tv_where = (TextView)layout.findViewById(R.id.ptextWhere); m_tv_notes = (TextView)layout.findViewById(R.id.ptextNotes); m_tv_what.setText(row.sSubject); switch((int)row.lPriority){ case 3: m_tv_priority.setText("low"); break; case 2: m_tv_priority.setText("medium"); break; case 1: m_tv_priority.setText("HIGH"); break; } m_tv_where.setText(row.sWhere); m_tv_notes.setText(row.sDescription); //Return the application context Toast toast = new Toast(ctx); //Set toast gravity to bottom //the height is 0 of course , because it has not been drawn yet //any way to get height? int height =layout.getHeight(); toast.setGravity(Gravity.TOP|Gravity.LEFT ,(int)x, (int)y ); //Set toast duration toast.setDuration(Toast.LENGTH_LONG); //Set the custom layout to Toast toast.setView(layout); //Display toast toast.show(); </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload