2012-07-18 83 views
0

我将选项卡作为活动。在其中一个选项卡中,我有一个搜索对话框。当我膨胀搜索结果时,我的选项卡消失。如何在保留标签的同时膨胀结果?如何膨胀布局?

下面是如何膨胀的结果:

LinearLayout layout = (LinearLayout) findViewById(R.id.quick_search); 

if(data==null) { 

    LinearLayout empty = (LinearLayout) mInflater.inflate(R.layout.empty, null); 

    layout.addView(empty); 

} 
else { 

    LinearLayout workRequest = (LinearLayout) mInflater.inflate(R.layout.quick_search, null); 

    layout.addView(workRequest); 
} 

其实我想到位LinearLayout“quick_search”来显示搜索结果,并确保上述“quick_search”的视图不会丢失。我目前的方法膨胀的结果占据整个屏幕。我怎样才能避免这种情况?

回答

0

如果quick_searchemptylayout_width和/或layout_height组的布局属性match_parent,那么他们会占据整个屏幕,当你膨胀他们。可以将它们设置为wrap_content或某些固定值以避免这种情况。

+0

它们设置为'wrap_content'。它仍然不起作用! – Harsh 2012-07-18 01:44:46

1

请参见以下链接

https://stackoverflow.com/a/2336047/1441666

RelativeLayout item = (RelativeLayout)findViewById(R.id.item); 
View child = getLayoutInflater().inflate(R.layout.child); 
item.addView(child); 
+0

我试过了。您的答案和我的代码之间的唯一区别是您已将孩子指定为视图而不是布局权限?它不起作用。我的意思是视图膨胀,但它占据了整个屏幕,我失去了我的标签底部。 – Harsh 2012-07-18 13:50:24