bringToFront工作一次後,它不再有效。爲什麼? 當你點擊一次它將視圖放在前面,但是當你嘗試恢復視圖時,它不再起作用。觸摸/點擊一直很好。爲什麼bringToFront只工作一次
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>
你想做什麼?單擊時隱藏另一個按鈕? – 2013-05-11 23:59:52
這只是一個測試,它不起作用。 – Chris 2013-05-12 00:05:24
我想我解決了。我必須將所有內容放在一個圖層中並使其無效 – Chris 2013-05-12 00:05:40