简体   繁体   English

如何在前面获取TextView的ID?

[英]How to get Id of TextView on the front?

If I have layout like this, how to get the id of the TextView on the front after I use bringToFront on any of this TextView ? 如果我有布局这样,如何获得的id TextView在前面我使用后bringToFront任何本的TextView

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">

<FrameLayout
    android:layout_width="match_parent"
    android:layout_height="wrap_content">

    <TextView
        android:id="@+id/textView"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="New Text 1" />

    <TextView
        android:id="@+id/textView2"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="New Text 2" />

    <TextView
        android:id="@+id/textView3"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="New Text 3" />
</FrameLayout>

According to the implementation of FrameLayout bringChildToFront 根据FrameLayout的实现带来bringChildToFront

public void bringChildToFront(View child) {
    int index = indexOfChild(child);
    if (index >= 0) {
        removeFromArray(index);
        addInArray(child, mChildrenCount);
        child.mParent = this;
        requestLayout();
        invalidate();
    }
}

you should be able to retrieve the view you are looking for with 您应该能够检索要查找的视图

frameLayoutInstance.getChildAt(frameLayoutInstance.getChildCount() - 1).getId()

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM