开发者

Unable to Add a subview to a LinearLayout with "Wrap_Content"

开发者 https://www.devze.com 2023-01-13 06:43 出处:网络
I\'m using data to build elements of a ViewGroup.The ViewGroup are LinearLayouts, except the leaves, which are TextViews.Because Data draws the hierarchy, I inflate the LinearLayouts and TextViews fro

I'm using data to build elements of a ViewGroup. The ViewGroup are LinearLayouts, except the leaves, which are TextViews. Because Data draws the hierarchy, I inflate the LinearLayouts and TextViews from individual XML files programatically on the fly.

My Problem: When I create a LinearLayout with the attribute wrap_content, then inflate a TextView or other LinearLayout into it, I can't get the parents (or enough of them, anyway) to redraw, respecting the new view. These LinearLayouts always seem to come out at 0 size, because when they are first cr开发者_Python百科eated (before their children are inflated), they wrap around nothing.

I've tried calling some stock methods of ViewGroup but nothing seems to work.


I wasn't logged in before. Below please find: Top parent XML, child layout XML, textView XML, and insertion code. Thanks for helping me out!

Top Parent Xml <LinearLayout android:orientation="vertical" android:layout_width="fill_parent" android:layout_height="fill_parent" android:id="@+id/tasks_view"> </LinearLayout>

Child Layout XML <LinearLayout android:orientation="vertical" android:id="@+id/task_line_tasks" android:layout_width="fill_parent" android:layout_height="wrap_content"/>

TextView XML <TextView xmlns:android="http://schemas.android.com/apk/res/android" android:textSize="10pt" android:layout_width="40dip" android:layout_height="fill_parent" android:background="#EAADEA" android:textColor="#000000"/>

Insertion code:
inflater.inflate(R.layout.person_line, tasks_view); newPersonLine = (LinearLayout) tasks_view.getChildAt(tasks_view.getChildCount()-1); newPersonLine.setId(i); newPersonName = (TextView)newPersonLine.getChildAt(0); newPersonName.setId(0); newPersonName.setText(people[i][0]);

0

精彩评论

暂无评论...
验证码 换一张
取 消