Android 快速开发之快速实现“我”界面

来源:互联网 发布:2017linux系统推荐 编辑:程序博客网 时间:2024/06/04 18:56

现在很多 APP 软件大部分都有我的 这个模块,然而今天给大家带来很方便的、快速的实现这个界面。效果图:
这里写图片描述

1、添加依赖

compile 'com.leon:lsettingviewlibrary:1.3.0'compile 'de.hdodenhof:circleimageview:2.1.0'

2、布局文件

<?xml version="1.0" encoding="utf-8"?><LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"    xmlns:leon="http://schemas.android.com/apk/res-auto"    xmlns:app="http://schemas.android.com/apk/res-auto"    xmlns:tools="http://schemas.android.com/tools"    android:layout_width="match_parent"    android:layout_height="match_parent"    android:orientation="vertical"    tools:context=".MainActivity">    <LinearLayout        android:layout_width="match_parent"        android:layout_height="150dp"        android:layout_marginBottom="16dp"        android:background="#fff"        android:gravity="center"        android:orientation="vertical">        <de.hdodenhof.circleimageview.CircleImageView            android:id="@+id/profile_image"            android:layout_width="96dp"            android:layout_height="96dp"            android:src="@drawable/e"            app:civ_border_color="#FFFFFF"            app:civ_border_width="2dp" />        <TextView            android:layout_width="match_parent"            android:layout_height="wrap_content"            android:gravity="center"            android:padding="10dp"            android:text="小飞象"            android:textSize="16sp" />    </LinearLayout>    <com.leon.lib.settingview.LSettingItem        android:id="@+id/item_one"        android:layout_width="match_parent"        android:layout_height="wrap_content"        leon:leftIcon="@drawable/ic_money"        leon:leftText="钱包" />    <com.leon.lib.settingview.LSettingItem        android:layout_width="match_parent"        android:layout_height="wrap_content"        leon:leftIcon="@drawable/ic_collect"        leon:leftText="收藏" />    <com.leon.lib.settingview.LSettingItem        android:layout_width="match_parent"        android:layout_height="wrap_content"        leon:leftIcon="@drawable/ic_photo"        leon:leftText="相册"        leon:rightStyle="iconHide"/>    <com.leon.lib.settingview.LSettingItem        android:id="@+id/item_four"        android:layout_width="match_parent"        android:layout_height="wrap_content"        android:theme="@style/MyCheckBox"        leon:leftIcon="@drawable/ic_card"        leon:leftText="卡包"        leon:rightStyle="iconCheck"/>    <com.leon.lib.settingview.LSettingItem        android:id="@+id/item_five"        android:layout_width="match_parent"        android:layout_height="wrap_content"        leon:leftIcon="@drawable/ic_face"        leon:leftText="表情" />    <com.leon.lib.settingview.LSettingItem        android:id="@+id/item_six"        android:layout_width="match_parent"        android:layout_height="wrap_content"        android:theme="@style/MyCheckBox"        leon:leftIcon="@drawable/ic_setting"        leon:rightStyle="iconSwitch"        leon:leftText="设置" />    <com.leon.lib.settingview.LSettingItem        android:layout_width="match_parent"        android:layout_height="wrap_content"        leon:isShowUnderLine="false"        leon:leftIcon="@drawable/ofm_feedback_icon"        leon:leftText="我的位置"        leon:rightStyle="iconSwitch" /></LinearLayout>

3、styles.xml 添加 MyCheckBox

<style name="MyCheckBox" parent="AppTheme">        <item name="colorControlNormal">#CCCCCC</item>        <item name="colorControlActivated">#0099CC</item></style>

4、MainActivity.java

package com.gyq.minedemo;import android.os.Bundle;import android.support.v7.app.AppCompatActivity;import android.widget.Toast;import com.leon.lib.settingview.LSettingItem;public class MainActivity extends AppCompatActivity {    @Override    protected void onCreate(Bundle savedInstanceState) {        super.onCreate(savedInstanceState);        setContentView(R.layout.activity_main);        //对一个控件进行点击事件        LSettingItem one =(LSettingItem)findViewById(R.id.item_one);        one.setmOnLSettingItemClick(new LSettingItem.OnLSettingItemClick() {            @Override            public void click() {                Toast.makeText(MainActivity.this,"点击了钱包",Toast.LENGTH_SHORT).show();            }        });    }}
阅读全文
0 0
原创粉丝点击