the xml version below properly handles height and width and the java doesn't what is the java missing?
xml
<?xml version="1.开发者_JAVA百科0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_height="fill_parent" android:layout_width="fill_parent"
android:orientation="horizontal">
<include android:id="@+id/cell1" layout="@layout/grid_text_view" />
<include android:id="@+id/cell2" layout="@layout/grid_text_view" />
</LinearLayout>
java
LinearLayout ll = new LinearLayout(this);
ll.setOrientation(LinearLayout.HORIZONTAL);
ll.setLayoutParams(new LayoutParams(LayoutParams.FILL_PARENT, LayoutParams.FILL_PARENT));
ll.addView((TextView)this.getLayoutInflater().inflate(R.layout.grid_text_view, null));
ll.addView((TextView)this.getLayoutInflater().inflate(R.layout.grid_text_view, null));
setContentView(ll);
grid_text_view
<TextView xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_height="fill_parent"
android:layout_width="0dip"
android:text="1"
android:textSize="20sp"
android:gravity="center"
android:layout_weight="1" />
I've tried a ll.invalidate() and it didn't work either? :(
screenshots at http://www.flickr.com/photos/48409507@N06/sets/72157623618407586/
You are passing null as the second parameter of the inflate() method. This will prevent the layout inflater from generating the appropriate LayoutParams for the inflated View. Instead of passing null, pass ll, the parent LinearLayout. Note that if you call inflate(R.layout.mytextview, ll, true) you don't even need to call addView(). The last parameter, true, means "attach the inflated view to the parent."
精彩评论