!!!!!安卓介面總是顯示載入進度條的問題,沒事別亂用ListFragment,安卓listfragment

來源:互聯網
上載者:User

!!!!!安卓介面總是顯示載入進度條的問題,沒事別亂用ListFragment,安卓listfragment

最近的安卓應用快完工了,但是個別介面有瑕疵,怎麼修改都解決不了,揮之不去的陰影。問題如下:

在介面上,資料已經載入完畢了,可還是有一股圓形的進度條,感覺它老是在載入什麼東西,嚴重影響介面美觀:

1. 布局用的是LinearLayout


2.介面布局用的是RelativeLayout



各種方法都試過了,當然都是基於布局檔案的修改,什麼fill_parent啦,alignBotton啦,換不同的layout啦,各種屬性試了個遍,都不行,為了這個布局問題整整折騰了三天。

反正,在布局檔案上再怎麼折騰可能都沒戲了。

靜下心來想想,問題會不會出在其他地方,而不是布局檔案?

回想起剛學Android那幾天,照著書上的例子寫,其中有提到ListView的部分,也提到了圓形的進度條,於是翻開書本,找到那個章節,忽然就柳暗花明了!



注意看照片中劃線的文字:“當ListView沒有內容可以顯示時... ... 顯示一個圓形進度條”,好吧,難道是問題出在應用的ListView?

那就來看看這個介面中的ListView是怎麼回事:

<?xml version="1.0" encoding="utf-8"?> <ScrollView xmlns:android="http://schemas.android.com/apk/res/android"    android:layout_width="fill_parent"     android:layout_height="fill_parent"><LinearLayout    android:id="@+id/fragmentContainer"    android:layout_width="fill_parent"     android:layout_height="wrap_content"     android:orientation="vertical" >        <LinearLayout>    <--表頭,忽略-->    </LinearLayout>        <ListView         android:id="@+id/list_uploadinfo_1"         android:layout_width="fill_parent"         android:layout_height="fill_parent"        android:dividerHeight="1px"        android:divider="#B8B8B8" >     </ListView>        <Button android:text="各網站上傳數量圖"/>    <LinearLayout>    <--表頭,忽略-->    </LinearLayout>        <ListView         android:id="@+id/list_uploadinfo_2"         android:layout_width="fill_parent"         android:layout_height="fill_parent"        android:dividerHeight="1px"              android:divider="#B8B8B8" >     </ListView>         <Button android:text="每月上傳數趨勢圖表"/>    </LinearLayout></ScrollView>



結構上,有兩個ListView,但他們都已經用資料填滿了,不存在沒有內容的問題。

那難道還有其他的ListView? 答案還真就是有其他的ListView,而且,是那個最大的ListView,卻被我忽略了:

public class UploadInfoFragment extends ListFragment { //注意,是繼承了ListFragmentprivate HashMap<String, Integer> monthQuantityMap;private HashMap<String, Integer> stationQuantityMap;...}

就是控制這個介面的Fragment,它繼承了ListFragment,也就需要自己的ListView來展示內容,但是只有剛才的兩個內部ListView填充了內容,外面這個大的沒有,所以才會有這個揮之不去的圓形進度條!!!

那怎麼辦?很簡單,既然並不需要往這個最大的ListView中填充資料,那何必要用ListFragment 呢?完全可以用普通的Fragment嘛。

其實,之所以這裡用的是ListFragment,完全是因為在做這個功能的時候,大部分代碼都是從其他功能搬過來的,所以把ListFragment也搬了過來。

然後進行修改,讓這個類繼承普通的 Fragment 即可:

public class UploadInfoFragment extends Fragment { //注意,用普通的Fragment即可private HashMap<String, Integer> monthQuantityMap;private HashMap<String, Integer> stationQuantityMap;...}
終於把討厭的圓形進度條趕走了,問題解決!




總結:有些常見的問題,網上隨便一查就有,但這些藏的比較深的問題,一般很難在網上直接查到,這個時候如果能仔細地取翻一翻書本,或許會有驚喜的發現~

另外,平時在看書的時候還是認真一點為好,這樣,有些細節就能印在腦子裡,說不定什麼時候就派上用場了~



問幾個安卓的問題? 1 fragment 2 listview 3 gridview

樓主懶得可以了,這些官方api裡面都有,給你個網址,自己去學習吧。developer.android.com/guide/components/index.html
 

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在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.