c# - Match_parent on dynamically added GridLayout -


i have textview inside gridlayout. gridlayout inflated dynamically @ runtime , added main layout. width of boxitem (the gridlayout) scaled correctly height seems wrap content. want height match parent.

main.axml:

<?xml version="1.0" encoding="utf-8"?> <linearlayout xmlns:android="http://schemas.android.com/apk/res/android"     android:orientation="vertical"     android:layout_width="match_parent"     android:layout_height="match_parent"     android:id="@+id/centerlayout"     android:background="#ffffff"/> 

border.xml:

<?xml version="1.0" encoding="utf-8"?> <shape xmlns:android="http://schemas.android.com/apk/res/android"     android:shape="rectangle" >   <stroke       android:width="2dp"       android:color="#000000" /> </shape> 

boxitem.axml:

<?xml version="1.0" encoding="utf-8"?> <gridlayout xmlns:android="http://schemas.android.com/apk/res/android"     android:layout_width="match_parent"     android:layout_height="match_parent"     android:rowcount="1"     android:columncount="2"     android:background="@drawable/border"     android:padding="10px">     <textview         android:text="test: "         android:id="@+id/textview1"         android:textcolor="#009900"         android:layout_width="wrap_content"         android:layout_height="wrap_content"         android:textsize="16sp" />     <textview         android:text="testy mctestface"         android:id="@+id/shelf"         android:textcolor="#009900"         android:layout_width="wrap_content"         android:layout_height="wrap_content"         android:textsize="16sp" /> </gridlayout> 

and here on create

protected override void oncreate(bundle bundle) {     base.oncreate(bundle);     setcontentview(resource.layout.main);     var view = layoutinflater.inflate(resource.layout.boxitem, null);     findviewbyid<linearlayout>(resource.id.centerlayout).addview(view); } 

you can add layoutparameters rule boxitem.axml when view found, example:

var view = layoutinflater.inflate(resource.layout.boxitem, null); view.layoutparameters = new viewgroup.layoutparams(viewgroup.layoutparams.matchparent, viewgroup.layoutparams.matchparent); findviewbyid<linearlayout>(resource.id.centerlayout).addview(view); 

this solve problem of layout parameters when dynamically add views.


Comments

Popular posts from this blog

android - InAppBilling registering BroadcastReceiver in AndroidManifest -

python Tkinter Capturing keyboard events save as one single string -

sql server - Why does Linq-to-SQL add unnecessary COUNT()? -