android - Positioning a Custom TableView in a RelativeLayout -


in main activity have relativelayout dynamically adding custom class called icontray extends tablelayout seen below. icontray takes arraylist , builds table. after table built , imageviews have been placed, want position table center screen. question is, how position icontray , do main activity or in itself.

my mainactivity:

import java.util.arraylist; import android.app.activity; import android.content.context; import android.content.dialoginterface; import android.content.dialoginterface.onclicklistener; import android.graphics.point; import android.os.bundle; import android.util.attributeset; import android.util.displaymetrics; import android.util.log; import android.view.display; import android.view.view; import android.view.view.onlongclicklistener; import android.widget.relativelayout; import android.widget.toast;  public class homefavesactivity extends activity implements onclicklistener, onlongclicklistener{      private static final string tag = "homefavescatovoty";     private arraylist<integer> micons = new arraylist<integer>();       /** called when activity first created. */     @override     public void oncreate(bundle savedinstancestate) {         super.oncreate(savedinstancestate);         setcontentview(r.layout.main);            log.v(tag, "created");          databasemanager db = new databasemanager(this);         db.getwritabledatabase();         db.addhomescreenicon(1);         db.addhomescreenicon(2);         db.addhomescreenicon(3);         /*db.addhomescreenicon(4);         db.addhomescreenicon(5);         db.addhomescreenicon(6);         db.addhomescreenicon(7);*/          getscreenicons(db);       }      private void getscreenicons(databasemanager db){         micons = db.gethomescreenicons();         log.v(tag, "list length:"+  micons.size());          icontray icontray = new icontray(this, micons, null);         relativelayout rl = (relativelayout)findviewbyid(r.id.main);          displaymetrics metrics = new displaymetrics();         getwindowmanager().getdefaultdisplay().getmetrics(metrics);          int screenwidth = metrics.heightpixels;         int screenheight =metrics.widthpixels;          relativelayout.layoutparams params = new relativelayout.layoutparams(screenwidth, screenheight);         params.addrule(relativelayout.center_in_parent);         icontray.setlayoutparams(params);         rl.addview(icontray);       }       public void onclick(dialoginterface arg0, int arg1) {         // todo auto-generated method stub      }      public boolean onlongclick(view v) {          toast.maketext(this, "woot",              toast.length_short).show();         return true;     }  } 

my layout xml

<?xml version="1.0" encoding="utf-8"?> <linearlayout xmlns:android="http://schemas.android.com/apk/res/android"     android:layout_width="fill_parent"     android:layout_height="fill_parent"     android:orientation="vertical" >      <textview         android:layout_width="fill_parent"         android:layout_height="wrap_content"         android:text="@string/hello" />      <relativelayout         android:id="@+id/main"         android:layout_width="wrap_content"         android:layout_height="match_parent"         android:layout_gravity="center"          >      </relativelayout>  </linearlayout> 

you can homefavesactivity. right before call rl.addview(icontray) in getscreenicons method, add code looks this:

relativelayout.layoutparams params = new relativelayout.layoutparams(somewidth, someheight); params.addrule(relativelayout.center_in_parent); icontray.setlayoutparams(params); 

you may have play little depending on how want height , width of icon tray work, should on right track.


Comments

Popular posts from this blog

delphi - How to convert bitmaps to video? -

jasper reports - Fixed header in Excel using JasperReports -

python - ('The SQL contains 0 parameter markers, but 50 parameters were supplied', 'HY000') or TypeError: 'tuple' object is not callable -