0
我有嵌套这样获取嵌套母
FrameLayout
CardView
LinearLayout
LinearLayout
LinearLayout
ImageButton
在侦听器ImageButton的意见,我设置了顶部的FrameLayout无形。
什么是比这更好,更动态的方式?
public void onButtonClicked(View view) {
((FrameLayout)view
.getParent()
.getParent()
.getParent()
.getParent()
.getParent())
.setVisibility(View.GONE);
}
我知道片段有一个'getView()'方法。我敢肯定,如果您试图获得顶视图,活动有类似的东西。否则,'findViewById'工作得很好 –
你可以显示你的布局xml文件代码,或者至少是'CardView'布局,即你想隐藏的布局吗? – Elye