基於Android ListView之載入提示_Android

來源:互聯網
上載者:User

程式員很多,遍地都是,高手也很多,但是懂設計的程式員並不多,我覺得我們不僅要成為一個coder還要成為一個designer。

我是一個比較注重ued的人,如果對一個app來說,程式是app的內涵那麼設計就是要體現app的外在美觀。

曾經看到一篇招聘使用者體驗設計師的資訊問道

     如果說,在我們身邊,設計師具有表達思想的力量;工程師具有實現思想的力量。

         那麼請問使用者體驗設計師具有什麼力量,有資格成為團隊成員?

每個人有每個的思想每個人有每個人的見解,這就不多講留給大家去思考。

我手機裝的應用並不多,稍微採集了一把手機上載入提示的應用截圖。

 alt= alt= alt= alt=以上是一些GooglePlay百度迅雷騰訊的應用內容載入的截圖。

一般載入提示有分三種,一種是Dialog一個帶進度圈的對話方塊,一種是輕提示Toast無焦點的提示器,還有一種就是內嵌在內容布局裡的位於最上層的視圖,以上應用貌似都是這種。

第一種,ProgressDialog一般成熟產品用的比較少,因為這個東西叫簡陋定製型不高。

第二種,Toast如果不定製的,很容易遭使用者的忽視甚至嫌棄。而ios上卻做的很好,如圖。

第三種,用的會比較多,一般會用到一個叫ViewStub的東西蓋在內容層的上層,其實也哭用線性布局,總之控製得當就行。

布局根布局是一個相對布局,然後是一個ListView,ListView下面是一個list為空白時顯示的View,再下面就是一個載入的ViewStub.

複製代碼 代碼如下:

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent" >

   

   
     <ListView
        android:id="@+id/lv"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"/>

     <ImageView android:id="@+id/ivEmpt"
         android:src="@drawable/netstate_icon"
         android:layout_centerInParent="true"
         android:layout_width="wrap_content"
        android:layout_height="wrap_content"/>

     <ViewStub
         android:id="@+id/vsLoadView"
         android:layout_centerInParent="true"
         android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout="@layout/loadding_view"
        />

</RelativeLayout>


java檔案
複製代碼 代碼如下:

package com.bvin.test.view;

import java.util.ArrayList;
import java.util.List;

import android.app.Activity;
import android.os.Bundle;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.view.ViewStub;
import android.widget.ArrayAdapter;
import android.widget.ListView;

public class MainActivity extends Activity {
    /** Called when the activity is first created. */

    private ListView lv = null;
    private View vEmpt = null;
    private ArrayAdapter<String> adapter = null;
    private List<String> sta = new ArrayList<String>();
    private ViewStub vsLoadView = null;
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.list_layout);
        lv = (ListView)findViewById(R.id.lv);
        adapter = new ArrayAdapter<String>(this,android.R.layout.simple_list_item_1,sta);
        lv.setAdapter(adapter);
        vEmpt=findViewById(R.id.ivEmpt);
        lv.setEmptyView(vEmpt);
        vsLoadView = (ViewStub)findViewById(R.id.vsLoadView);
    }

    @Override
    public boolean onCreateOptionsMenu(Menu menu) {
        // TODO Auto-generated method stub
        menu.add(0, 0, 0, "添加");
        menu.add(1, 1, 1, "刪除");
        menu.add(2, 2, 2, "清空");
        return super.onCreateOptionsMenu(menu);
    }

    @Override
    public boolean onOptionsItemSelected(MenuItem item) {
        // TODO Auto-generated method stub
        switch(item.getItemId()){

        case 0:
            sta.add("薩芬i阿雙方i");
            if(!vsLoadView.isShown())
            vsLoadView.inflate();
            break;
        case 1:
            if(sta.size()>0)
            sta.remove(sta.size()-1);
            vsLoadView.setVisibility(View.GONE);
            break;
        case 2:
            sta.clear();
            vsLoadView.setVisibility(View.VISIBLE);
            break;

        }
        adapter.notifyDataSetChanged();
        return super.onOptionsItemSelected(item);
    }

   
}


 alt=

前面那個載入的logo,後面的是內容為空白的時候顯示的Logo。

得出的結論是:

1.ViewStub的inflate()方法只能調用一次,調用了inflate()調用setVisibility(View.VISIBLE);設定為可見,但是調用了setVisibility(View.VISIBLE);就不能再調用inflate(),因為這個方法setVisibility是先把布局inflate出來,然後再設定可見。

2. listView.setEmptyView();這個方法也有點講究,就是EmptyView與Listview在同一個容器裡,負責無效。

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.