Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
在我的应用程序中,我将 textview、imageview 从一个线性布局拖放到另一个线性布局。如何以编程方式找到 textview 或 imageview 的当前位置,无论它是第一个布局还是第二个布局。
您可以通过调用获取视图父级view.getParent(),然后将其转换为LinearLayout. 然后,我只需检查父 IDview.getId()并检查它是否等于R.id.nameOfYourFirstLayout或R.id.nameOfYourSecondLayout
view.getParent()
LinearLayout
view.getId()
R.id.nameOfYourFirstLayout
R.id.nameOfYourSecondLayout
您可以尝试检索父视图并检查它的 ID:
View parent = (View)view.getParent();
还是布局也是动态的?