I am creating a banner of 5 images. So that first image will be display with a Text and after 1 second second image will be display with a text and after 1 second other and till 5 images.

So this work as a banner. and image will be show one by one between 1 second period left to right slide.

But i am confused how can i develop it. Please expert any library or other ..

有帮助吗?

解决方案

You need to keep track of the waiting process in another thread and then update the UI.

ImageButton _YourBanner  = (ImageButton)finndViewById(R.id.yourBanner);


    final Handler myHandler = new Handler(){

    @Override
    public void handleMessage(Message msg) {
          //put some condition like:
              int counter = msg.getData().getInt("Counter");
              switch(counter){
                 case 0: 
                     _YourBanner.setImageResource(R.drawable.yourFirstImage);
                     break;
                 case 1:
                   ...
              }
    }};

    (new Thread(new Runnable() {
    @Override
    public void run() {
            int counter = 0;
                while (counter <6){

                  Thread.sleep(1000);   

                  Message msg = myHandler.obtainMessage();                
                      Bundle bundle = new Bundle();
                      bundle.putInt("Counter", counter);
                      msg.setData(bundle);
                      counter++;
                      if (counter == 6)
                      counter = 0;
                      myHandler.sendMessage(msg);

                }
          }})).start();

其他提示

Use this for your UI design in XML

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/header_layout" android:layout_width="fill_parent"
android:layout_height="wrap_content" android:orientation="horizontal">

<!-- home button -->
<ImageButton android:id="@+id/header_home_button"
    android:src="@drawable/menu_info" android:layout_height="wrap_content"
    android:layout_width="wrap_content" />

<!-- header text -->
<TextView android:id="@+id/header_title" android:layout_width="200dip"
    android:layout_height="wrap_content" android:gravity="center"
    android:text="Todays recipe :" android:textSize="20dp"
    android:textStyle="bold" />

</LinearLayout>  

Use this in java file

ImageButton _home  = (ImageButton)finndViewById(R.id.header_home_button);
_home.setImageResource(R.drawable.anyimage);

TextView _title  = (TextView )finndViewById(R.id.header_title);
_title.setText("Your title");
许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top