2019-11-27 10:51:43 NewActivity 阅读数 20

效果图如下:

关闭状态:

点击一级条目展开状态:

使用如下:

1.在主界面布局里使用:

<ExpandableListView
    android:layout_marginLeft="16dp"
    android:layout_marginRight="16dp"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:id="@+id/el_fragment_third"
    ></ExpandableListView>

2.一级条目布局

item_expandable_levelone.xml

<?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:layout_marginTop="16dp"
    android:orientation="vertical">
    <RelativeLayout
        android:id="@+id/item_expandable_rl"
        android:layout_width="match_parent"
        android:layout_height="56dp"
        android:background="@drawable/bg_expandable_circle">

        <ImageView
            android:id="@+id/item_expandable_deletecircle"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:paddingRight="7dp"
            android:paddingBottom="7dp"
            android:src="@mipmap/icon_expandable_deletecircle" />

        <ImageView
            android:id="@+id/item_expandable_user"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_centerVertical="true"
            android:paddingLeft="16dp"
            android:src="@mipmap/icon_expandable_user" />

        <TextView
            android:id="@+id/item_expandable_circlename"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_centerVertical="true"
            android:layout_marginLeft="12dp"
            android:layout_toRightOf="@id/item_expandable_user"
            android:text="@string/expandable_item_001"
            android:textColor="#232323"
            android:textSize="18sp" />

        <ImageView
            android:id="@+id/item_expandable_left"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_alignParentRight="true"
            android:layout_centerVertical="true"
            android:layout_marginRight="16dp"
            android:src="@mipmap/icon_expandable_left" />
    </RelativeLayout>
</LinearLayout>

3.二级条目布局

item_expandable_leveltwo.xml

<?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:orientation="vertical">

    <RelativeLayout
        android:id="@+id/rr_location_layout"
        android:layout_width="match_parent"
        android:layout_height="40dp"
        android:layout_marginLeft="10dp"
        android:layout_marginTop="5dp"
        android:layout_marginBottom="5dp"
        android:layout_marginRight="10dp"
        android:background="@drawable/bg_item_circle_shadow_location"
        >

        <ImageView
            android:layout_centerVertical="true"
            android:id="@+id/iv_location_head"
            android:layout_width="24dp"
            android:layout_height="24dp"
            android:layout_marginLeft="16dp"
            android:src="@mipmap/logo_profile_head" />

        <TextView
            android:id="@+id/tv_location_id"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_marginLeft="12dp"
            android:layout_centerVertical="true"
            android:layout_toRightOf="@id/iv_location_head"
            android:text="ID:5468nkk"
            android:textColor="#333333"
            android:textSize="18sp" />

        <ImageView
            android:id="@+id/iv_location_icon"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_alignParentRight="true"
            android:layout_marginTop="8dp"
            android:layout_marginRight="24dp"
            />
     
        <ImageView
            android:padding="8dp"
            android:id="@+id/iv_location_delete"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:src="@mipmap/icon_expandable_delete"
            android:layout_alignParentRight="true"
            android:layout_marginRight="16dp"
            android:layout_centerVertical="true"
            />
    </RelativeLayout>
</LinearLayout>

4.UserInfo:

public class UserInfo {
    private int imgPath;
    private String id;
    private String Name;
    private String Latitude;
    private String Longitude;

    public void setIsTrue(boolean aTrue) {
        isTrue = aTrue;
    }

    public boolean getIsTrue() {
        return isTrue;
    }

    private boolean isTrue;//点击


    public void setImgPath(int imgPath) {
        this.imgPath = imgPath;
    }

    public void setId(String id) {
        this.id = id;
    }

    public void setName(String name) {
        Name = name;
    }

    public void setLatitude(String latitude) {
        Latitude = latitude;
    }

    public void setLongitude(String longitude) {
        Longitude = longitude;
    }

    public int getImgPath() {
        return imgPath;
    }

    public String getId() {
        return id;
    }

    public String getName() {
        return Name;
    }

    public String getLatitude() {
        return Latitude;
    }

    public String getLongitude() {
        return Longitude;
    }
}

5.activity里代码(只写跟控件有关的)

private ExpandableListView mel_linkageView;
     @Override
     protected void onCreate(Bundle savedInstanceState) {
         super.onCreate(savedInstanceState);
         setContentView(R.layout.frag_third);
 
         initView();
     }
     private void initView() {
        mel_linkageView = view.findViewById(R.id.el_fragment_third);
        mel_linkageView.setGroupIndicator(null);//去掉自带箭头
        mel_linkageView.setDividerHeight(0);
        //userListInfo 为要展示的数据,添加过程省略。。。假设里面已经有数据
        List<List<UserInfo>> userListInfo =new ArrayList<List<UserInfo>>();
        List<UserInfo> userInfos =new ArrayList<UserInfo>();
        List<UserInfo> userInfos =new ArrayList<UserInfo>();
        UserInfo userinfo =new UserInfo(); userinfo.set...等等
        userListInfo.add(userInfos);
        userListInfo.add(userInfos2);     

       
        String[] groups = {"My Circle","My Circle2"};
        MyExpandableAdapterTypeTwo myAdapter = new MyExpandableAdapterTypeTwo(groups,userListInfo,this);
        mel_linkageView.setAdapter(myAdapter);
        //设置ExpandableListView各级列表全部展开
        if(myAdapter !=null){
                for (int i = 0; i < myAdapter.getGroupCount(); i++) {
                    mel_linkageView.expandGroup(i);//全部展开
                }
        }

     }   

 

注:1.userListInfo 是我要展示的二级数据,本来的动态获取的。如果做测试的话也可以自己new一些UserInfo放到list里面,在把           list放入userListInfo。

       2.group是我展示的一级数据,因为我的一级列表是固定的,所以group的长度也是固定的,这个也可以动态获取。

       3.其中setGroupIndicator是去掉ExpandableListView自带的箭头,setDividerHeight是去除条目之间带的横线。

       4.MyExpandableAdapterTypeTwo 负责主要展示

 

6.MyExpandableAdapterTypeTwo:

public class MyExpandableAdapterTypeTwo extends BaseExpandableListAdapter {

    private String[] groups;
    private List<List<UserInfo>> childs;
    private Activity activity;

    public MyExpandableAdapterTypeTwo(String[] gro, List<List<UserInfo>> chi, Activity act) {
        groups = gro;
        childs = chi;
        activity = act;
    }

    /*一级列表个数*/
    @Override
    public int getGroupCount() {
        return groups.length;
    }

    /*每个二级列表的个数*/
    @Override
    public int getChildrenCount(int groupPosition) {
        return childs.get(groupPosition).size();
    }

    /*一级列表中单个item*/
    @Override
    public Object getGroup(int groupPosition) {
        return groups[groupPosition];
    }

    /*二级列表中单个item*/
    @Override
    public Object getChild(int groupPosition, int childPosition) {
        return childs.get(groupPosition).get(childPosition);
    }

    @Override
    public long getGroupId(int groupPosition) {
        return groupPosition;
    }

    @Override
    public long getChildId(int groupPosition, int childPosition) {
        return childPosition;
    }

    /*每个item的id是否固定,一般为true*/
    @Override
    public boolean hasStableIds() {
        return true;
    }

    /*#TODO 填充一级列表
     * isExpanded 是否已经展开
     * */
    @Override
    public View getGroupView(int groupPosition, boolean isExpanded, View convertView, ViewGroup parent) {
        if (convertView == null) {
            convertView = activity.getLayoutInflater().inflate(R.layout.item_expandable_levelone, null);
        }
        ImageView mIvLeft = convertView.findViewById(R.id.item_expandable_left);
        TextView mTvCircle = convertView.findViewById(R.id.item_expandable_circlename);
        mTvCircle.setText(groups[groupPosition]);
        //控制展开和关闭时一级条目右侧的图标
        if (isExpanded) {
            mIvLeft.setImageResource(R.mipmap.icon_expandable_leftdown);
        } else {
            mIvLeft.setImageResource(R.mipmap.icon_expandable_left);
        }

        return convertView;
    }

    /*#TODO 填充二级列表*/
    @Override
    public View getChildView(final int groupPosition, final int childPosition, boolean isLastChild, View convertView, ViewGroup parent) {
        if (convertView == null) {
            convertView = activity.getLayoutInflater().inflate(R.layout.item_expandable_leveltwo, null);
        }
        ImageView mIvHead = convertView.findViewById(R.id.iv_location_head);
        TextView mTvId = convertView.findViewById(R.id.tv_location_id);
        ImageView mIvDelete = convertView.findViewById(R.id.iv_location_delete);

        final UserInfo mUserInfo = childs.get(groupPosition).get(childPosition);
        mTvId.setText(mUserInfo.getId());
        if (mUserInfo.getImgPath() == 0) {
            mIvHead.setImageResource(R.mipmap.icon_contacts_1);
        } else {
            mIvHead.setImageResource(mUserInfo.getImgPath());
        }

        mIvDelete.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {

            }
        });

        return convertView;
    }

    /*二级列表中每个能否被选中,如果有点击事件一定要设为true*/
    @Override
    public boolean isChildSelectable(int groupPosition, int childPosition) {
        return true;
    }
2019-11-26 10:41:53 qq_26658275 阅读数 20

本文是基于Android5.1的代码

废话不多说,直接上硬菜!(突出重点)

packages\inputmethods\LatinIME\java\res\values-sw600dp\config-per-form-factor.xml

<?xml version="1.0" encoding="utf-8"?>
<!--
/*
**
** Copyright 2013, The Android Open Source Project
**
** Licensed under the Apache License, Version 2.0 (the "License");
** you may not use this file except in compliance with the License.
** You may obtain a copy of the License at
**
**     http://www.apache.org/licenses/LICENSE-2.0
**
** Unless required by applicable law or agreed to in writing, software
** distributed under the License is distributed on an "AS IS" BASIS,
** WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
** See the License for the specific language governing permissions and
** limitations under the License.
*/
-->

<!-- Configuration values for Small Tablet. -->
<resources>
    <bool name="config_enable_show_key_preview_popup_option">false</bool>
    <!-- Whether or not Popup on key press is enabled by default -->
    <bool name="config_default_key_preview_popup">false</bool>
    <bool name="config_default_sound_enabled">false</bool>
    <bool name="config_enable_show_voice_key_option">false</bool>
    <bool name="config_key_selection_by_dragging_finger">false</bool>
    <!-- Showing more keys keyboard, just above the touched point if true, aligned to the             
    key iffalse -->
    <bool name="config_show_more_keys_keyboard_at_touched_point">false</bool>
    <bool name="config_use_fullscreen_mode">false</bool>
</resources>

将 "config_default_sound_enabled"属性值改为:false   // 关闭键盘声音

2015-12-21 00:10:07 flyfly121 阅读数 462
mBluetoothAdapter = BluetoothAdapter.getDefaultAdapter();
if (mBluetoothAdapter == null) {
    Toast.makeText(this, "不支持蓝牙", Toast.LENGTH_SHORT).show();
} else if (!mBluetoothAdapter.isEnabled()) {
    Intent enableBTIntent = new Intent(BluetoothAdapter.ACTION_REQUEST_ENABLE);
    startActivityForResult(enableBTIntent, REQUEST_ENABLE_BT);
}


private BroadcastReceiver receiver = new BroadcastReceiver() {
    @Override
    public void onReceive(Context context, Intent intent) {
        int state = intent.getIntExtra(BluetoothAdapter.EXTRA_STATE, 0);
        switch (state) {
            case BluetoothAdapter.STATE_TURNING_ON:
                Toast.makeText(MainActivity.this, "Bluetooth正在打开", Toast.LENGTH_SHORT).show();
                break;
            case BluetoothAdapter.STATE_ON:
                Toast.makeText(MainActivity.this, "Bluetooth已打开", Toast.LENGTH_SHORT).show();
                break;
            case BluetoothAdapter.STATE_TURNING_OFF:
                Toast.makeText(MainActivity.this, "Bluetooth正在关闭", Toast.LENGTH_SHORT).show();
                break;
            case BluetoothAdapter.STATE_OFF:
                Toast.makeText(MainActivity.this, "Bluetooth已关闭", Toast.LENGTH_SHORT).show();
                break;
        }
    }
};


@Override
protected void onResume() {
    super.onResume();
    registerReceiver(receiver, new IntentFilter(BluetoothAdapter.ACTION_STATE_CHANGED));
}

@Override
protected void onStop() {
    super.onStop();
    unregisterReceiver(receiver);
}

2015-10-29 21:34:00 weixin_33973609 阅读数 18

最近抽时间学习一下Android,做个笔记:

布局xml:

   <LinearLayout
                     android:id="@+id/date_label"
                    android:layout_width="35dp"
                    android:layout_height="wrap_content"
                    android:background="@layout/slipercornerenable"
                    android:gravity="right|center"
                    android:padding="1dp" >

                    <LinearLayout
                        android:layout_width="18dp"
                        android:layout_height="18dp"
                        android:background="@layout/slipercircle" >
                    </LinearLayout>
                </LinearLayout>
@Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
    view = View.inflate(this, layout.listview_select_date, null);
//设置两个选项的监听
            view.findViewById(id.date_label).setOnClickListener(this);
            view.findViewById(id.auto_update_date).setOnClickListener(this);

}

切换方法:

 
    void switchControl(View view) {
        LinearLayout llLayout = (LinearLayout) view;
        int tag = 0;
        if (view.getTag() != null) {
            tag = Integer.parseInt(view.getTag().toString());
        }
        if (tag == 0) {
            // 打开
            view.setTag(1);
            view.setBackgroundResource(layout.slipercornerenable);
            llLayout.setGravity(Gravity.RIGHT);
        } else {
            // 关闭
            view.setTag(0);
            view.setBackgroundResource(layout.slipercornerdisenable);
            llLayout.setGravity(Gravity.LEFT);
        }
    }

 

实现onClick事件:

    @Override
    public void onClick(View arg0) {
        int cid = arg0.getId();
        switch (cid) {         
        case id.date_label:// 日期标签
            switchControl(arg0);
            return;            
        case id. auto_update_date:// 自动同步日期
            switchControl(arg0);
            return;
        default:
            break;
        }
        super.onClick(arg0);
    }

 

开发中效果:

运行效果:

 

2013-09-13 16:13:01 skyinmyheart 阅读数 1196
<ProgressBar
android:id="@+id/progressBar"
android:layout_width="40dp"
android:layout_height="40dp"
android:layout_gravity="center_vertical"
android:layout_centerVertical="true"
android:background="@drawable/bitmap"
android:indeterminateDrawable="@drawable/progress_small" />

<rotate xmlns:android="http://schemas.android.com/apk/res/android"
android:drawable="@drawable/circle"
android:pivotX="50%"
android:pivotY="50%"
android:fromDegrees="0"
android:toDegrees="360" />
没有更多推荐了,返回首页