mardi 26 septembre 2017

How to detect Gravity of XML item

What is the correct way to detect the gravity flags used for an XML item? I'm trying to achieve the following:

  1. If the gravity of my TableLayout (myTbl) is set to Gravity.TOP, then I want the gravity to be set to Gravity.CENTER_VERTICAL
  2. Else if the gravity of my TableLayout (myTbl) is set to Gravity.CENTER_VERTICAL, then I want the gravity to be set to Gravity.BOTTOM

private Button myBtn;
private TableLayout myTbl;

public void btn_click(View view) {
    if (myTbl.getGravity() == Gravity.TOP) {
        myTbl.setGravity(Gravity.CENTER_VERTICAL);
    } else if (myTbl.getGravity() == Gravity.CENTER_VERTICAL) {
        tblMain.setGravity(Gravity.BOTTOM);
    }
}

I tried using getGravity() but API 24+ is required, which is not what I want.The API used in my project is lower than 24.

Aucun commentaire:

Enregistrer un commentaire