Nam Jayer Nam Jayer - 2 months ago 19
Android Question

Android - Onclick Image bring front of text

How to Onclick Image bring front of text?

I have a layout and i use imageView1.bringToFront(); in button onclick event but not working!

<Button
android:id="@+id/btn"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Button" />


<ImageView
android:id="@+id/imageView1"
android:visibility="visible"
android:layout_width="match_parent"
android:layout_height="247dp"
android:layout_gravity="center"
android:src="@android:drawable/sym_def_app_icon" />

<TextView
android:id="@+id/textView1"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:gravity="center"
android:text="Frame Demo"
android:textAppearance="?android:attr/textAppearanceLarge" />


and MainActivity

btn = (Button)findViewById(R.id.btn);
imageView1 = (ImageView)findViewById(R.id.imageView1);

btn.setOnClickListener(new OnClickListener() {

@Override
public void onClick(View v) {
// TODO Auto-generated method stub
imageView1.bringToFront();
}
});


Can you help me? Thanks!

Answer

DO this :boolean isclicked=true;

 btn.setOnClickListener(new OnClickListener() {
    @Override
    public void onClick(View v) {
        // TODO Auto-generated method stub
      if(isClicked){
         firstClick();
        isClicked=false
    }else{
     secondClick();
      isClicked=true;
       }
        }

      firstClick(){
      ((View)Imageview.getParent()).requestLayout();
        Imageview.bringChildToFront(this);}
        });
       }

     secondClick(){
   ///Do Your code
 }

Let me know if it works