java - Differences between View create with xml - View create with code -


there difference when i'm trying add programmatically relativelayout , when use directly xml view.

if copy paste several relativelayout in container_tabs works..

and when try inflate relativelayout file (exactly same container_tabs) result different , doesn't works.

how fill view programmatically

    @bindview(r.id.container_tabs)     protected linearlayout mlinearlayoutcontainertabs;      private list<custombookingtab> mbookingtabslist = new arraylist<>();      private void initcustombuttonstabs() {        mbookingtabslist.add(new custombookingtab(this, enumbookingtab.booking_tab_calendar, r.drawable.ic_calendar_white));        mbookingtabslist.add(new custombookingtab(this, enumbookingtab.booking_tab_time, r.drawable.ic_clock));          (int = 0; < mbookingtabslist.size(); i++) {             mlinearlayoutcontainertabs.addview(mbookingtabslist.get(i).getrelativelayoutbookingtab(), i);        }     } 

how inflate view xml file (custombookingtab constructor)

mrelativelayoutbookingtab = (relativelayout) inflater.inflate(r.layout.booking_tab, null); 

main view

    <linearlayout         android:layout_width="match_parent"         android:layout_height="wrap_content"         android:layout_margintop="-29dp"         android:orientation="horizontal">          <linearlayout             android:layout_width="0dp"             android:layout_height="wrap_content"             android:layout_weight="1"             android:gravity="center"             android:orientation="horizontal">              <linearlayout                 android:id="@+id/container_tabs"                 android:layout_width="match_parent"                 android:layout_height="match_parent"                 android:layout_gravity="center"                 android:gravity="center"                 android:orientation="horizontal">                  <!-- tab item -->                 <relativelayout                     android:layout_width="0dp"                     android:layout_height="70dp"                     android:layout_gravity="center"                     android:layout_weight="1">                      <framelayout                         android:layout_width="match_parent"                         android:layout_height="wrap_content">                          <imageview                             android:layout_width="70dp"                             android:layout_height="70dp"                             android:layout_alignparentleft="true"                             android:background="@drawable/circle_blue_button_border_white"                             android:padding="21dp"                             android:src="@drawable/ic_calendar_white"                             android:text="button"                             android:textcolor="#ffffff"                             android:textsize="30sp" />                      </framelayout>                  </relativelayout>               </linearlayout>          </linearlayout>      </linearlayout> 

is there way that? wrong?

there difference add view xml , inflating view anatomically.

but in case of relative layout when preparing xml there many relative properties used set different views xml .

and when adding views dynamically using relative layout should use option of addrule bellow :

 relativelayout relativelayout  = new relativelayout(getactivity());         relativelayout.layoutparams layoutparams = new relativelayout.layoutparams(relativelayout.layoutparams.wrap_content,layoutparams.wrap_content);         button button1 = new button(this);         button1.setid(1);         button button2 = new button(this);         button2.setid(2);         relativelayout.addview(button1);         relativelayout.addview(button2);         relativelayout.layoutparams lp = (relativelayout.layoutparams) button1.getlayoutparams();         lp.addrule(relativelayout.right_of, button2.getid());         lp.addrule(relativelayout.left_of, button2.getid());         lp.addrule(relativelayout.align_end, button2.getid());         lp.addrule(relativelayout.align_left, button2.getid());         lp.addrule(relativelayout.align_baseline, button2.getid());         lp.addrule(relativelayout.align_parent_bottom, button2.getid());         lp.addrule(relativelayout.align_parent_left, button2.getid());         lp.addrule(relativelayout.align_parent_right, button2.getid());         lp.addrule(relativelayout.above, button2.getid());         lp.addrule(relativelayout.align_parent_top, button2.getid());         lp.addrule(relativelayout.start_of, button2.getid());         lp.addrule(relativelayout.align_right, button2.getid());         lp.addrule(relativelayout.align_parent_end, button2.getid());         lp.addrule(relativelayout.end_of, button2.getid()); 

almost relative layout properties can dynamically through addrull .


Comments

Popular posts from this blog

python - How to insert QWidgets in the middle of a Layout? -

python - serve multiple gunicorn django instances under nginx ubuntu -

module - Prestashop displayPaymentReturn hook url -