gpt4 book ai didi

android - 为什么 bringToFront 只工作一次

转载 作者:太空狗 更新时间:2023-10-29 13:30:12 25 4
gpt4 key购买 nike

bringToFront 工作一次,之后就不再工作了。为什么?当您单击一次时,它会将该 View 带到前面,但是当您尝试恢复该 View 时,它不再有效。触摸/点击始终正常。

    View view1,view2,view3,view4; 
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
//sets the Bundle

//code to initiate and putting the views in layout
view1= findViewById(R.id.button1);
view2= findViewById(R.id.button2);

view1.setOnClickListener(new OnClickListener() {

@Override
public void onClick(View arg0) {
// TODO Auto-generated method stub
Log.i("onClick","1");
view1.bringToFront();
view1.invalidate();
view2.invalidate();
}
});
view2.setOnClickListener(new OnClickListener() {

@Override
public void onClick(View arg0) {
// TODO Auto-generated method stub
Log.i("onClick","2");
view2.bringToFront();
view1.invalidate();
view2.invalidate();
}
});
}

这是xml

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingBottom="@dimen/activity_vertical_margin"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
tools:context=".MainActivity" >


<TextView
android:id="@+id/button2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="16dp"
android:layout_marginLeft="30dp"
android:text="Button2ButtonButton"
android:textColor="#00ff00"
android:textSize="60dp" />

<TextView
android:id="@+id/button1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="16dp"
android:layout_marginLeft="170dp"
android:text="Button1ButtonButton"
android:textColor="#ff0000"
android:textSize="60dp" />

</RelativeLayout>

最佳答案

我想我解决了。我必须将所有内容都放在一个图层中并使其无效。

关于android - 为什么 bringToFront 只工作一次,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16502800/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com