我有android项目,我必须更改最后exxpanded组(将崩溃)的布局和单击的组。 onGroupClick方法我有:
int cnt=list.getChildCount();
//set layout to all groups (for closed group)
for(int i = 0; i < cnt; i`enter code here`++){
View group = adapter.getGroupView(i, false,
null, list);
LinearLayout childLayout = (LinearLayout) group.findViewById(R.id.newsLayout); childLayout.setBackgroundResource(R.layout.group_layout_shape);
}
// set layout of clicked group
LinearLayout groupLayout = (LinearLayout) v.findViewById(R.id.newsLayout);
groupLayout.setBackgroundResource(R.layout.group_layout_opened_shape);`enter code here`
它改变了点击组的布局(会扩展),但是不会改变组的布局,那会消失:(可以帮助我
答案 0 :(得分:0)
您不应该使用此方法,因为它仅用于使用inflater的图片,颜色,布局,这有一个非常有趣的方法
膨胀(R.layout.childLayout,ParentView,true);
您首先放置要膨胀的图层,第二个 - 将包含子图层和第三个图层的父图层 - 布尔变量必须为true才能保持膨胀。
活动中的示例:
public class MainActivity extends ActionBarActivity {
LayoutInflater inflater;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
inflater = (LayoutInflater)getSystemService(LAYOUT_INFLATER_SERVICE);
RelativeLayout parentView= (RelativeLayout) findViewById(R.id.mainLayout);
View v = (View) inflater.inflate(R.layout.child_layout, parentView, true);
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.menu_main, menu);
return true;
}
@Override
public boolean onOptionsItemSelected(MenuItem item) {
// Handle action bar item clicks here. The action bar will
// automatically handle clicks on the Home/Up button, so long
// as you specify a parent activity in AndroidManifest.xml.
int id = item.getItemId();
//noinspection SimplifiableIfStatement
if (id == R.id.action_settings) {
return true;
}
return super.onOptionsItemSelected(item);
}
}