android - Re-apply layout_centerHorizontal programmatically -


i have custom relative layout view, have dynamically change background resource. problem is, after setting background, layout_centerhorizontal property of children removed , items no longer horizontally centered. trying figure out how re-apply it. here layout:

<?xml version="1.0" encoding="utf-8"?> <relativelayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools" android:id="@+id/marker_background" android:layout_width="wrap_content" android:layout_height="wrap_content" tools:background="@drawable/ic_markerdefault" >  <imageview     android:id="@+id/marker_category"     android:layout_width="20dp"     android:layout_height="20dp"     tools:src="@drawable/ic_bike"     android:layout_centerhorizontal="true"     />  <textview     android:id="@+id/marker_price"     android:layout_width="wrap_content"     android:layout_height="wrap_content"     android:layout_below="@+id/marker_category"     tools:text="$10"     android:layout_centerhorizontal="true"     style="@style/markerpricetext"      /> </relativelayout> 

and code:

private imageview mimgcategory; private textview mtextprice; ...  private void setbackground(int state) {       switch (state) {         case default:             this.setbackgroundresource(r.drawable.ic_markerdefault);             break;         case active:             this.setbackgroundresource(r.drawable.ic_markerselected);             break;         case visited:             this.setbackgroundresource(r.drawable.ic_markervisited);             break;         default:             this.setbackgroundresource(r.drawable.ic_markerdefault);             break;     }      relativelayout.layoutparams lp = (layoutparams) mimgcategory.getlayoutparams();     lp.addrule(relativelayout.center_horizontal, true);     mimgcategory.setlayoutparams(lp);      relativelayout.layoutparams lp2 = (layoutparams) mtextprice.getlayoutparams();     lp2.addrule(center_horizontal, true);     mtextprice.setlayoutparams(lp2); }  .... 

change layout_width , layout_height "match_parent"


Comments

Popular posts from this blog

c++ - Delete matches in OpenCV (Keypoints and descriptors) -

java - Could not locate OpenAL library -

sorting - opencl Bitonic sort with 64 bits keys -