Naham Soft Naham Soft - 6 months ago 34
Android Question

how to send the front image view to the end of elements and so on for framelayout elements android

I have create a new layout which is type of FrameLayout and I have added four elements of image view I want to take the first image view to the end programmatically

in short reorder the elements of framelayout programmatically. suppose we do that listen to button clickListener

<FrameLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="@+id/framelayout">
<ImageView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@mipmap/a20141008_091817"
android:id="@+id/i1"/>
<ImageView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@mipmap/a20141008_091819"
android:id="@+id/i2"/>
<ImageView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@mipmap/a20141008_091821"
android:id="@+id/i3"/>
<ImageView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@mipmap/a20141008_091823"
android:id="@+id/i4"/>

</FrameLayout>


I appreciated any help.

Answer

first of all. Thanks so much for every one try to help me. then i figure out my problem in good practice way and I wish to share it with you may any one will need it in future. the steps

  1. create a frameLayout as in the xml in my question
  2. add your image into frameLayout
  3. create a java file and connect it to the xml
  4. we must to know the ids of all the images into the framlayout
  5. create a timer which will change the order of image in X seconds
  6. get the count of all the images into the framLayout
  7. create Intager var which will determine which is next of image to bring to front
  8. still calling the timer to work in x times as i mentioned
  9. create method to stop the timer if we want in my case I stop the timer in the onPause() method

    this is the java file which will do all the above steps. wish it help any one

public class FrameLayout5 extends AppCompatActivity {

FrameLayout frameLayout; 
Handler handler;             // this class will work as timer for change the order of images in delay 
List<Integer> views;    //  this Array list will store all the ids of all the ImageViews into framelayout 
int counter;        //  this counter will help us to find the next element to bring it to front 

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_frame_layout5);
    Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
    setSupportActionBar(toolbar);

    frameLayout = (FrameLayout) findViewById(R.id.framelayout);
    handler = new Handler();
    views = new ArrayList<Integer>();
    counter=0;

    // get all the children of framelayout 
    for (int i = 0; i < frameLayout.getChildCount() ; i++) {
        views.add(frameLayout.getChildAt(i).getId());
    }

    handler.postDelayed(runnable, 1000); // 1000 mean that this method will excute every 1 second 


}

Runnable runnable = new Runnable() {
    @Override
    public void run() {

        int i=counter%(frameLayout.getChildCount());    
            counter++;
        ImageView a = (ImageView) findViewById(views.get(i));

        frameLayout.bringChildToFront(a);

        handler.postDelayed(runnable, 1000);
        Log.d("run", "called "+i);
    }
};

@Override
protected void onStop() {
    super.onStop();
    handler.removeCallbacks(runnable);
}

}

@ExpensiveBelly @ishmaelMakitla

Comments