91超碰碰碰碰久久久久久综合_超碰av人澡人澡人澡人澡人掠_国产黄大片在线观看画质优化_txt小说免费全本

溫馨提示×

溫馨提示×

您好,登錄后才能下訂單哦!

密碼登錄×
登錄注冊×
其他方式登錄
點擊 登錄注冊 即表示同意《億速云用戶服務條款》

關于 ExpandableListView 的列子

發布時間:2020-08-05 19:11:29 來源:網絡 閱讀:378 作者:IT達仁 欄目:移動開發

喜歡顯示好友QQ那樣的列表,可以展開,可以收起,在android中,以往用的比較多的是listview,雖然可以實現列表的展示,但在某些情況下,我們還是希望用到可以分組并實現收縮的列表,那就要用到android的ExpandableListView,今天研究了一下這個的用法,也參考了很多資料動手寫了一個小demo,實現了基本的功能,但界面優化方面做得還不夠好,有待改進,素材采用了Q版三國殺武將的圖片,很有愛哈哈,下面直接上效果圖以及源代碼~! 

關于 ExpandableListView 的列子         關于 ExpandableListView 的列子          關于 ExpandableListView 的列子

 

 

main.xml的布局很簡單啦,只是一個ExpandableListView 就OK了

但值得簡單說下的是 android:cacheColorHint="#00000000",這個設置可以去除拖動view時背景變成黑色的效果

android:listSelector="#00000000" ,可以去除選中時的***底色

 

關于 ExpandableListView 的列子

 1 <?xml version="1.0" encoding="utf-8"?>
 2 <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
 3     android:layout_width="fill_parent"
 4     android:layout_height="fill_parent"
 5     android:orientation="vertical" >
 6     <ExpandableListView 
 7         android:id="@+id/list"
 8         android:layout_width="fill_parent"
 9         android:layout_height="fill_parent"
10         android:background="#ffffff"
11         android:cacheColorHint="#00000000"
12         android:listSelector="#00000000" 
13         >
14     </ExpandableListView> 
15 </LinearLayout>  
16 

關于 ExpandableListView 的列子

 


java代碼: 

 

關于 ExpandableListView 的列子

package com.eyu.activity_test;

import android.app.Activity;
import android.graphics.Color;
import android.os.Bundle;
import android.view.Gravity;
import android.view.View;
import android.view.ViewGroup;
import android.view.Window;
import android.widget.AbsListView;
import android.widget.BaseExpandableListAdapter;
import android.widget.ExpandableListAdapter;
import android.widget.ExpandableListView;
import android.widget.ExpandableListView.OnChildClickListener;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;
import android.widget.Toast;

public class ExpandableList extends Activity{

    protected void onCreate(Bundle savedInstanceState) {
        // TODO Auto-generated method stub
        super.onCreate(savedInstanceState);
        requestWindowFeature(Window.FEATURE_NO_TITLE);
        setContentView(R.layout.main);

        final ExpandableListAdapter adapter = new BaseExpandableListAdapter() {
            //設置組視圖的圖片
            int[] logos = new int[] { R.drawable.wei, R.drawable.shu,R.drawable.wu};
            //設置組視圖的顯示文字
            private String[] generalsTypes = new String[] { "魏", "蜀", "吳" };
            //子視圖顯示文字
            private String[][] generals = new String[][] {
                    { "夏侯惇", "甄姬", "許褚", "郭嘉", "司馬懿", "楊修" },
                    { "馬超", "張飛", "劉備", "諸葛亮", "黃月英", "趙云" },
                    { "呂蒙", "陸遜", "孫權", "周瑜", "孫尚香" }

            };
            //子視圖圖片
            public int[][] generallogos = new int[][] {
                    { R.drawable.xiahoudun, R.drawable.zhenji,
                            R.drawable.xuchu, R.drawable.guojia,
                            R.drawable.simayi, R.drawable.yangxiu },
                    { R.drawable.machao, R.drawable.zhangfei,
                            R.drawable.liubei, R.drawable.zhugeliang,
                            R.drawable.huangyueying, R.drawable.zhaoyun },
                    { R.drawable.lvmeng, R.drawable.luxun, R.drawable.sunquan,
                            R.drawable.zhouyu, R.drawable.sunshangxiang } };
            
            //自己定義一個獲得文字信息的方法
            TextView getTextView() {
                AbsListView.LayoutParams lp = new AbsListView.LayoutParams(
                        ViewGroup.LayoutParams.FILL_PARENT, 64);
                TextView textView = new TextView(
                        ExpandableList.this);
                textView.setLayoutParams(lp);
                textView.setGravity(Gravity.CENTER_VERTICAL);
                textView.setPadding(36, 0, 0, 0);
                textView.setTextSize(20);
                textView.setTextColor(Color.BLACK);
                return textView;
            }

            
            //重寫ExpandableListAdapter中的各個方法
            @Override
            public int getGroupCount() {
                // TODO Auto-generated method stub
                return generalsTypes.length;
            }

            @Override
            public Object getGroup(int groupPosition) {
                // TODO Auto-generated method stub
                return generalsTypes[groupPosition];
            }

            @Override
            public long getGroupId(int groupPosition) {
                // TODO Auto-generated method stub
                return groupPosition;
            }

            @Override
            public int getChildrenCount(int groupPosition) {
                // TODO Auto-generated method stub
                return generals[groupPosition].length;
            }

            @Override
            public Object getChild(int groupPosition, int childPosition) {
                // TODO Auto-generated method stub
                return generals[groupPosition][childPosition];
            }

            @Override
            public long getChildId(int groupPosition, int childPosition) {
                // TODO Auto-generated method stub
                return childPosition;
            }

            @Override
            public boolean hasStableIds() {
                // TODO Auto-generated method stub
                return true;
            }

            @Override
            public View getGroupView(int groupPosition, boolean isExpanded,
                    View convertView, ViewGroup parent) {
                // TODO Auto-generated method stub
                LinearLayout ll = new LinearLayout(
                        ExpandableList.this);
                ll.setOrientation(0);
                ImageView logo = new ImageView(ExpandableList.this);
                logo.setImageResource(logos[groupPosition]);
                logo.setPadding(50, 0, 0, 0);
                ll.addView(logo);
                TextView textView = getTextView();
                textView.setTextColor(Color.BLACK);
                textView.setText(getGroup(groupPosition).toString());
                ll.addView(textView);

                return ll;
            }

            @Override
            public View getChildView(int groupPosition, int childPosition,
                    boolean isLastChild, View convertView, ViewGroup parent) {
                // TODO Auto-generated method stub
                LinearLayout ll = new LinearLayout(
                        ExpandableList.this);
                ll.setOrientation(0);
                ImageView generallogo = new ImageView(
                        ExpandableList.this);
                generallogo
                        .setImageResource(generallogos[groupPosition][childPosition]);
                ll.addView(generallogo);
                TextView textView = getTextView();
                textView.setText(getChild(groupPosition, childPosition)
                        .toString());
                ll.addView(textView);
                return ll;
            }

            @Override
            public boolean isChildSelectable(int groupPosition,
                    int childPosition) {
                // TODO Auto-generated method stub
                return true;
            }

        };

        ExpandableListView expandableListView = (ExpandableListView) findViewById(R.id.list);
        expandableListView.setAdapter(adapter);
        
        
        //設置item點擊的監聽器
        expandableListView.setOnChildClickListener(new OnChildClickListener() {

            @Override
            public boolean onChildClick(ExpandableListView parent, View v,
                    int groupPosition, int childPosition, long id) {

                Toast.makeText(
                        ExpandableList.this,
                        "你點擊了" + adapter.getChild(groupPosition, childPosition),
                        Toast.LENGTH_SHORT).show();

                return false;
            }
        });
    }
}

向AI問一下細節

免責聲明:本站發布的內容(圖片、視頻和文字)以原創、轉載和分享為主,文章觀點不代表本網站立場,如果涉及侵權請聯系站長郵箱:is@yisu.com進行舉報,并提供相關證據,一經查實,將立刻刪除涉嫌侵權內容。

AI

武威市| 固镇县| 大新县| 三穗县| 乌拉特中旗| 宁远县| 会昌县| 舒城县| 建平县| 卢龙县| 乐业县| 安图县| 马龙县| 全椒县| 大姚县| 二连浩特市| 高台县| 宁武县| 泸溪县| 昌江| 绥芬河市| 营山县| 科尔| 石景山区| 宝丰县| 永丰县| 西平县| 华容县| 社旗县| 富锦市| 图片| 丰宁| 四会市| 永兴县| 汾西县| 玛多县| 思茅市| 烟台市| 南宫市| 临澧县| 海兴县|