<ruby id="bdb3f"></ruby>

    <p id="bdb3f"><cite id="bdb3f"></cite></p>

      <p id="bdb3f"><cite id="bdb3f"><th id="bdb3f"></th></cite></p><p id="bdb3f"></p>
        <p id="bdb3f"><cite id="bdb3f"></cite></p>

          <pre id="bdb3f"></pre>
          <pre id="bdb3f"><del id="bdb3f"><thead id="bdb3f"></thead></del></pre>

          <ruby id="bdb3f"><mark id="bdb3f"></mark></ruby><ruby id="bdb3f"></ruby>
          <pre id="bdb3f"><pre id="bdb3f"><mark id="bdb3f"></mark></pre></pre><output id="bdb3f"></output><p id="bdb3f"></p><p id="bdb3f"></p>

          <pre id="bdb3f"><del id="bdb3f"><progress id="bdb3f"></progress></del></pre>

                <ruby id="bdb3f"></ruby>

                企業??AI智能體構建引擎,智能編排和調試,一鍵部署,支持知識庫和私有化部署方案 廣告
                android中為我們提供了3種adapter來為各種各樣的list來適配數據,其ArrayAdapter 對只有純字符列表的list適應,如果遇到list的每個item都有添加幾項的情況,如下圖,有頭像,名字,作品,人氣等,那么ArrayAdapter就不是適用了,就可以使用SimpleAdapter 了,而baseAdapter 用起來對初學者有點難,建議使用simpleAdapter。首先來看整體的布局文件: ~~~ <?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="match_parent" android:orientation="vertical" > <TextView style="?android:attr/textAppearanceLarge" android:layout_width="match_parent" android:layout_height="50dp" android:gravity="center" android:text="@string/tab_author" /> <ListView android:id="@+id/author_list" android:layout_width="match_parent" android:layout_height="wrap_content" android:scrollbars="none"> </ListView> </LinearLayout> ~~~ ![](https://box.kancloud.cn/2016-04-25_571e2151679e4.jpg) 其中定義了一個列表的標題,下面定義了一個列表,列表中的scroolbars=“none”是隱藏滾動條。接下來就要為每個item設置布局了,分別有頭像,作者,作品,人氣。 ~~~ <?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="wrap_content" android:background="#FFFFFFFF" android:orientation="vertical" > <View android:layout_width="match_parent" android:layout_height="7dp" android:background="#FFdddddd" > </View> <LinearLayout android:layout_width="match_parent" android:layout_height="wrap_content" android:orientation="horizontal" > <ImageView android:id="@+id/list_item_author_touxiang" android:layout_width="80dp" android:layout_height="80dp" android:layout_margin="10dp" android:src="@drawable/icon_stub" /> <LinearLayout android:layout_width="wrap_content" android:layout_height="match_parent" android:layout_marginBottom="10dp" android:layout_marginRight="10dp" android:layout_marginTop="10dp" android:orientation="vertical" > <TextView android:id="@+id/list_item_author" android:layout_width="wrap_content" android:layout_height="0dp" android:layout_weight="1" android:text="作者" android:textSize="18sp"/> <TextView android:id="@+id/list_item_author_zuopin" android:layout_width="wrap_content" android:layout_height="0dp" android:layout_weight="1" android:gravity="bottom" android:text="作品:" android:textColor="#FF777777" /> <TextView android:id="@+id/list_item_author_renqi" android:layout_width="wrap_content" android:layout_height="0dp" android:layout_weight="1" android:gravity="bottom" android:text="人氣:" android:textColor="#FF777777" /> </LinearLayout> </LinearLayout> </LinearLayout> ~~~ ![](https://box.kancloud.cn/2016-04-25_571e215186e93.jpg) 然后我們就可以在java代碼中編寫程序,來實現一個漂亮的列表; ~~~ public class AuthorListFragment extends Fragment { private ListView listView; private View authorList; private String[] authors = {"周杰倫","王力宏","郭敬明", "周杰倫","王力宏","郭敬明", "周杰倫","王力宏","郭敬明"}; private String[] zuopin = {"《搞笑》《東風破》","《落葉歸根》","《圍城》《小時代》", "《搞笑》《東風破》","《落葉歸根》","《圍城》《小時代》", "《搞笑》《東風破》","《落葉歸根》","《圍城》《小時代》"}; private String[] renqi = {"9999","12345","98687","9999","12345","98687","9999","12345","98687"}; private int[] touxiang = {R.drawable.zhoujielun,R.drawable.wanglihong,R.drawable.guojingm, R.drawable.zhoujielun,R.drawable.wanglihong,R.drawable.guojingm, R.drawable.zhoujielun,R.drawable.wanglihong,R.drawable.guojingm}; @Override public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { authorList = inflater.inflate(R.layout.author_list, container,false); viewHolder(); List<HashMap<String,Object>> data = new ArrayList<HashMap<String,Object>>(); for(int i = 0; i < authors.length; i++){ HashMap<String,Object> map = new HashMap<String,Object>(); map.put("touxiang", touxiang[i]); map.put("name", authors[i]); map.put("zuopin", "作品:"+zuopin[i]); map.put("renqi", "人氣:"+renqi[i]); data.add(map); } SimpleAdapter adapter = new SimpleAdapter(getActivity(), data, R.layout.author_list_item, new String[]{"touxiang","name","zuopin","renqi"}, new int[]{R.id.list_item_author_touxiang, R.id.list_item_author, R.id.list_item_author_zuopin, R.id.list_item_author_renqi}); listView.setAdapter(adapter); return authorList; } private void viewHolder() { listView = (ListView) authorList.findViewById(R.id.author_list); } } ~~~ 我這是在一個fragment里面實現的,大家可以在Activity里面試試,都是能 行的。我在真機上面運行的,我截個圖給大家看看: ![](https://box.kancloud.cn/2016-04-25_571e21519ae61.jpg) ? 到此為止,simpleadapter就能實現很漂亮的列表界面。 祝大家開開興興,每天進步一點!88
                  <ruby id="bdb3f"></ruby>

                  <p id="bdb3f"><cite id="bdb3f"></cite></p>

                    <p id="bdb3f"><cite id="bdb3f"><th id="bdb3f"></th></cite></p><p id="bdb3f"></p>
                      <p id="bdb3f"><cite id="bdb3f"></cite></p>

                        <pre id="bdb3f"></pre>
                        <pre id="bdb3f"><del id="bdb3f"><thead id="bdb3f"></thead></del></pre>

                        <ruby id="bdb3f"><mark id="bdb3f"></mark></ruby><ruby id="bdb3f"></ruby>
                        <pre id="bdb3f"><pre id="bdb3f"><mark id="bdb3f"></mark></pre></pre><output id="bdb3f"></output><p id="bdb3f"></p><p id="bdb3f"></p>

                        <pre id="bdb3f"><del id="bdb3f"><progress id="bdb3f"></progress></del></pre>

                              <ruby id="bdb3f"></ruby>

                              哎呀哎呀视频在线观看