2

我正在创建一个包含 5 个图像的横幅。因此,第一张图像将显示文本,1 秒后第二张图像将显示文本,1 秒后显示其他图像,直到 5 张图像。

所以这个工作作为一个横幅。并且图像将在 1 秒左右的幻灯片之间一张一张地显示。

但我很困惑如何开发它。请专家任何图书馆或其他..

4

2 回答 2

1

您需要在另一个线程中跟踪等待过程,然后更新 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();
于 2013-09-17T04:45:59.570 回答
0

将其用于 XML 中的 UI 设计

<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>  

在java文件中使用它

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");
于 2013-09-17T04:41:44.593 回答