android - RelativeLayout -> match_parent is not the same size with parent view -



android - RelativeLayout -> match_parent is not the same size with parent view -

i've made simple application illustrate problem. brief explanation: app contains 1 activity. it's root view tablelayout. latter filled tablerow elements are, in turn, inflated "row.xml". here code:

testactivity.java

public class testactivity extends activity { @override public void oncreate(bundle savedinstancestate) { super.oncreate(savedinstancestate); layoutinflater inflater=getlayoutinflater(); tablelayout table=new tablelayout(this); setcontentview(table); tablerow row; for(int i=0;i<3;i++){ row=(tablerow)inflater.inflate(r.layout.row, null, true); table.addview(row); } } }

in row.xml tablerow root element, has kid - relativelayout. pay attending relativelayout's property android:layout_width="match_parent". row.xml:

<?xml version="1.0" encoding="utf-8"?> <tablerow xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="wrap_content" android:background="@drawable/background" > <relativelayout android:id="@+id/announcement_row_relative_layout" android:layout_width="match_parent" android:layout_height="match_parent" > </relativelayout>

then run project, open hierarchyviewer tool , inspect width of table rows , corresponding relative layouts - see 320 , 0 respectively. why aren't same (320 , 320) if declared "match_parent" in relative layout? attach 2 images can observe width of elements own.

your problem here : row=(tablerow)inflater.inflate(r.layout.row, null, true);

you have inflate row this:

row=(tablerow)inflater.inflate(r.layout.row, table, false);

this way layoutparams loaded xml file.

android relativelayout

Comments

Popular posts from this blog

How do I check if an insert was successful with MySQLdb in Python? -

delphi - blogger via idHTTP : error 400 bad request -

postgresql - ERROR: operator is not unique: unknown + unknown -