• 简单微信界面


    2016/5/13

    完成四个基本界面

    MainActivity

    package com.example.administrator.lchat;
    
    import android.content.IntentFilter;
    import android.support.v4.app.Fragment;
    import android.support.v4.app.FragmentTransaction;
    import android.support.v7.app.AppCompatActivity;
    import android.os.Bundle;
    import android.view.View;
    import android.view.Window;
    import android.widget.ImageView;
    import android.widget.TextView;
    import com.example.administrator.lchat.R;
    
    public class MainActivity extends AppCompatActivity {
        private ImageView iv_add;
        private ImageView iv_search;
        private Fragment[] fragments;
        public FragmentCoversation homefragment;
        private FragmentFriends contactlistfragment;
        private FragmentFind findfragment;
        private FragmentProfile profilefragment;
    
        private ImageView[] imagebuttons;
        private TextView[] textviews;
        private int index;
        // 当前fragment的index
        private int currentTabIndex;
    
    
        @Override
        protected void onCreate(Bundle savedInstanceState) {
            super.onCreate(savedInstanceState);
            setContentView(R.layout.activity_main);
    
            iv_add = (ImageView) this.findViewById(R.id.iv_add);
            iv_search = (ImageView) this.findViewById(R.id.iv_search);
            initView();
        }
    
        private void initView() {
    
            homefragment = new FragmentCoversation();
            contactlistfragment = new FragmentFriends();
            findfragment = new FragmentFind();
            profilefragment = new FragmentProfile();
            fragments = new Fragment[] { homefragment, contactlistfragment,
                    findfragment, profilefragment };
            imagebuttons = new ImageView[4];
            imagebuttons[0] = (ImageView) findViewById(R.id.ib_weixin);
            imagebuttons[1] = (ImageView) findViewById(R.id.ib_contact_list);
            imagebuttons[2] = (ImageView) findViewById(R.id.ib_find);
            imagebuttons[3] = (ImageView) findViewById(R.id.ib_profile);
    
            imagebuttons[0].setSelected(true);
            textviews = new TextView[4];
            textviews[0] = (TextView) findViewById(R.id.tv_weixin);
            textviews[1] = (TextView) findViewById(R.id.tv_contact_list);
            textviews[2] = (TextView) findViewById(R.id.tv_find);
            textviews[3] = (TextView) findViewById(R.id.tv_profile);
            textviews[0].setTextColor(0xFF45C01A);
            // 添加显示第一个fragment
            getSupportFragmentManager().beginTransaction()
                    .add(R.id.fragment_container, homefragment)
                    .add(R.id.fragment_container, contactlistfragment)
                    .add(R.id.fragment_container, profilefragment)
                    .add(R.id.fragment_container, findfragment)
                    .hide(contactlistfragment).hide(profilefragment)
                    .hide(findfragment).show(homefragment).commit();
        }
    
        public void onTabClicked(View view) {
            switch (view.getId()) {
                case R.id.re_weixin:
                    index = 0;
                    break;
                case R.id.re_contact_list:
                    index = 1;
                    break;
                case R.id.re_find:
                    index = 2;
                    break;
                case R.id.re_profile:
                    index = 3;
                    break;
    
            }
    
            if (currentTabIndex != index) {
                FragmentTransaction trx = getSupportFragmentManager()
                        .beginTransaction();
                trx.hide(fragments[currentTabIndex]);
                if (!fragments[index].isAdded()) {
                    trx.add(R.id.fragment_container, fragments[index]);
                }
                trx.show(fragments[index]).commit();
            }
            imagebuttons[currentTabIndex].setSelected(false);
            // 把当前tab设为选中状态
            imagebuttons[index].setSelected(true);
            textviews[currentTabIndex].setTextColor(0xFF999999);
            textviews[index].setTextColor(0xFF45C01A);
            currentTabIndex = index;
        }
    
    }

    main_activity.xml

    <?xml version="1.0" encoding="utf-8"?>
    <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
        android:id="@+id/mainLayout"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:background="#ffffff" >
    
        <RelativeLayout
            android:id="@+id/title"
            android:layout_width="match_parent"
            android:layout_height="@dimen/height_top_bar"
            android:layout_alignParentTop="true"
            android:background="@color/common_top_bar_blue" >
    
            <TextView
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_alignParentLeft="true"
                android:layout_centerVertical="true"
                android:layout_marginLeft="10dp"
                android:text="微信"
                android:textColor="#ffffff"
                android:textSize="18sp" />
    
            <ImageView
                android:id="@+id/iv_add"
                android:layout_width="56dp"
                android:layout_height="match_parent"
                android:layout_alignParentRight="true"
                android:clickable="true"
                android:src="@drawable/main_activity_add" />
    
            <ImageView
                android:id="@+id/iv_search"
                android:layout_width="56dp"
                android:layout_height="match_parent"
                android:layout_toLeftOf="@id/iv_add"
                android:clickable="true"
                android:src="@drawable/main_activity_search" />
        </RelativeLayout>
    
        <LinearLayout
            android:id="@+id/main_bottom"
            android:layout_width="match_parent"
            android:layout_height="54dp"
            android:layout_alignParentBottom="true"
            android:background="#ffffff"
            android:gravity="center_vertical"
            android:orientation="horizontal" >
    
            <RelativeLayout
                android:id="@+id/re_weixin"
                android:layout_width="0dp"
                android:layout_height="match_parent"
                android:layout_weight="1"
                android:onClick="onTabClicked"
                android:padding="3dp" >
    
                <ImageView
                    android:id="@+id/ib_weixin"
                    android:layout_width="wrap_content"
                    android:layout_height="28dp"
                    android:layout_centerHorizontal="true"
                    android:background="#ffffff"
                    android:focusable="false"
                    android:scaleType="centerInside"
                    android:src="@drawable/tab_weixin" />
    
                <TextView
                    android:id="@+id/tv_weixin"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:layout_below="@id/ib_weixin"
                    android:layout_centerHorizontal="true"
                    android:layout_marginTop="3dp"
                    android:text="微信"
                    android:textColor="#9A9A9A"
                    android:textSize="12sp" />
    
                <TextView
                    android:id="@+id/unread_msg_number"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:layout_alignParentRight="true"
                    android:layout_marginRight="10dp"
                    android:background="@drawable/unread_count_bg"
                    android:gravity="center"
                    android:text="7"
                    android:textColor="@android:color/white"
                    android:textSize="12sp" />
            </RelativeLayout>
    
            <RelativeLayout
                android:id="@+id/re_contact_list"
                android:layout_width="0dp"
                android:layout_height="match_parent"
                android:layout_weight="1"
                android:onClick="onTabClicked"
                android:padding="3dp" >
    
                <ImageView
                    android:id="@+id/ib_contact_list"
                    android:layout_width="wrap_content"
                    android:layout_height="28dp"
                    android:layout_centerHorizontal="true"
                    android:background="#ffffff"
                    android:focusable="false"
                    android:scaleType="centerInside"
                    android:src="@drawable/tab_contact_list" />
    
                <TextView
                    android:id="@+id/tv_contact_list"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:layout_below="@id/ib_contact_list"
                    android:layout_centerHorizontal="true"
                    android:layout_marginTop="3dp"
                    android:text="通讯录"
                    android:textColor="#9A9A9A"
                    android:textSize="12sp" />
    
                <TextView
                    android:id="@+id/unread_address_number"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:layout_alignParentRight="true"
                    android:layout_marginRight="10dp"
                    android:background="@drawable/unread_count_bg"
                    android:gravity="center"
                    android:text="7"
                    android:textColor="@android:color/white"
                    android:textSize="12sp" />
            </RelativeLayout>
    
            <RelativeLayout
                android:id="@+id/re_find"
                android:layout_width="0dp"
                android:layout_height="match_parent"
                android:layout_weight="1"
                android:onClick="onTabClicked"
                android:padding="3dp" >
    
                <ImageView
                    android:id="@+id/ib_find"
                    android:layout_width="wrap_content"
                    android:layout_height="28dp"
                    android:layout_centerHorizontal="true"
                    android:background="#ffffff"
                    android:focusable="false"
                    android:scaleType="centerInside"
                    android:src="@drawable/tab_find" />
    
                <TextView
                    android:id="@+id/tv_find"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:layout_below="@id/ib_find"
                    android:layout_centerHorizontal="true"
                    android:layout_marginTop="3dp"
                    android:text="发现"
                    android:textColor="#9A9A9A"
                    android:textSize="12sp" />
            </RelativeLayout>
    
            <RelativeLayout
                android:id="@+id/re_profile"
                android:layout_width="0dp"
                android:layout_height="match_parent"
                android:layout_weight="1"
                android:onClick="onTabClicked"
                android:padding="3dp" >
    
                <ImageView
                    android:id="@+id/ib_profile"
                    android:layout_width="wrap_content"
                    android:layout_height="28dp"
                    android:layout_centerHorizontal="true"
                    android:background="#ffffff"
                    android:focusable="false"
                    android:scaleType="centerInside"
                    android:src="@drawable/tab_profile" />
    
                <TextView
                    android:id="@+id/tv_profile"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:layout_below="@id/ib_profile"
                    android:layout_centerHorizontal="true"
                    android:layout_marginTop="3dp"
                    android:text="我"
                    android:textColor="#9A9A9A"
                    android:textSize="12sp" />
            </RelativeLayout>
        </LinearLayout>
    
        <View
            android:id="@+id/view_temp"
            android:layout_width="match_parent"
            android:layout_height="0.1dp"
            android:layout_above="@id/main_bottom"
            android:background="#d6d6d6" />
    
        <RelativeLayout
            android:id="@+id/fragment_container"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:layout_above="@id/view_temp"
            android:layout_below="@id/title" />
    
    </RelativeLayout>
    FragmentCoversation.java
    public class FragmentCoversation extends Fragment {
    
        LayoutInflater inflater;
        @Override
        public View onCreateView(LayoutInflater inflater, ViewGroup container,
                                 Bundle savedInstanceState) {
            return inflater.inflate(R.layout.fragment_home, container, false);
        }
    }
    fragment_home.xml
    <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
         android:background="@color/common_bg"
        android:orientation="vertical" >
    
        <include
            android:id="@+id/rl_error_item"
            layout="@layout/chat_neterror_item"
           />
    
        
          <ListView
             android:cacheColorHint="#00000000"
            android:id="@+id/list"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:background="@android:color/transparent"
            android:divider="@null"
            />
    </LinearLayout>
    FragmentFriends.java
    public class FragmentFriends extends Fragment {
        private LayoutInflater infalter;
        ListView listView;
        private String[] strs = new String[]{ "first","second","third","fourth","fifth"};
    
        @Override
        public View onCreateView(LayoutInflater inflater, ViewGroup container,
                                 Bundle savedInstanceState) {
            return inflater
                    .inflate(R.layout.fragment_contactlist, container, false);
        }
    
        @Override
        public void onActivityCreated(Bundle savedInstanceState) {
            super.onActivityCreated(savedInstanceState);
    
            if (savedInstanceState != null)
                return;
    
            listView = (ListView) getView().findViewById(R.id.list);
    
            infalter=LayoutInflater.from(getActivity());
            View headView = infalter.inflate(R.layout.item_contact_list_header,
                    null);
            listView.addHeaderView(headView);
            View footerView = infalter.inflate(R.layout.item_contact_list_footer,
                    null);
            listView.addFooterView(footerView);
            listView.setAdapter(new ArrayAdapter<String>(getActivity(),android.R.layout.simple_list_item_1,strs));
        }
    }
    fragment_contactlist.xml
    <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:background="#EBEBEB"
        android:orientation="vertical" >
    
        <FrameLayout
            android:layout_width="match_parent"
            android:layout_height="match_parent" >
    
            <RelativeLayout
                android:id="@+id/rl_list"
                android:layout_width="match_parent"
                android:layout_height="match_parent" >
    
                <LinearLayout
                    android:id="@+id/ll_loading"
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:layout_marginLeft="10dp"
                    android:layout_marginTop="2dp"
                    android:gravity="center_vertical"
                    android:visibility="gone" >
    
                    <ProgressBar
                        android:layout_width="28dp"
                        android:layout_height="28dp" />
    
                    <TextView
                        android:id="@+id/tv_loaing"
                        android:layout_width="wrap_content"
                        android:layout_height="wrap_content"
                        android:layout_marginLeft="6dp"
                        android:text="正在刷新联系人..." />
                </LinearLayout>
    
                <ListView
                    android:id="@+id/list"
                    android:layout_width="match_parent"
                    android:layout_height="match_parent"
                    android:layout_below="@id/ll_loading"
                    android:background="@android:color/transparent"
                    android:footerDividersEnabled="false"
                    android:descendantFocusability="afterDescendants"
    
    
                    android:fastScrollEnabled="false" />
    
                <TextView
                    android:id="@+id/floating_header"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:layout_centerInParent="true"
                    android:background="@drawable/show_head_toast_bg"
                    android:gravity="center"
                    android:paddingLeft="25dp"
                    android:paddingRight="25dp"
                    android:textColor="@android:color/white"
                    android:textSize="40sp"
                    android:visibility="invisible" />
    
            </RelativeLayout>
        </FrameLayout>
    
    
    </LinearLayout>
    FragmentFind.java
    public class FragmentFind  extends Fragment {
        @Override
        public View onCreateView(LayoutInflater inflater, ViewGroup container,
                                 Bundle savedInstanceState) {
            return inflater.inflate(R.layout.fragment_find, container, false);
        }
    }
    fragment_find.xml
    <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:background="#EBEBEB"
        android:orientation="vertical" >
    
        <RelativeLayout
            android:id="@+id/re_friends"
            android:layout_width="match_parent"
            android:layout_height="48dp"
            android:layout_marginTop="20dp"
            android:background="@drawable/btn_list_item_bg"
            android:clickable="true"
            android:paddingLeft="12dp" >
    
            <ImageView
                android:id="@+id/iv_friends"
                android:layout_width="24dp"
                android:layout_height="24dp"
                android:layout_alignParentLeft="true"
                android:layout_centerVertical="true"
                android:layout_marginLeft="12dp"
                android:src="@drawable/find_friends" />
    
            <TextView
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_centerVertical="true"
                android:layout_marginLeft="20dp"
                android:layout_toRightOf="@id/iv_friends"
                android:text="朋友圈"
                android:textColor="#353535"
                android:textSize="16sp" />
        </RelativeLayout>
    
        <RelativeLayout
            android:id="@+id/re_erweima"
            android:layout_width="match_parent"
            android:layout_height="48dp"
            android:layout_marginTop="20dp"
            android:background="@drawable/btn_list_item_bg"
            android:clickable="true"
            android:paddingLeft="12dp" >
    
            <ImageView
                android:id="@+id/iv_erweima"
                android:layout_width="24dp"
                android:layout_height="24dp"
                android:layout_alignParentLeft="true"
                android:layout_centerVertical="true"
                android:layout_marginLeft="12dp"
                android:src="@drawable/find_erweima" />
    
            <TextView
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_centerVertical="true"
                android:layout_marginLeft="20dp"
                android:layout_toRightOf="@id/iv_erweima"
                android:text="扫一扫"
                android:textColor="#353535"
                android:textSize="16sp" />
    
            <View
                android:layout_width="match_parent"
                android:layout_height="0.1dp"
                android:layout_alignParentBottom="true"
                android:layout_marginRight="12dp"
                android:background="#dadada" />
        </RelativeLayout>
    
        <RelativeLayout
            android:id="@+id/re_yaoyiyao"
            android:layout_width="match_parent"
            android:layout_height="48dp"
            android:background="@drawable/btn_list_item_bg"
            android:clickable="true"
            android:paddingLeft="12dp" >
    
            <ImageView
                android:id="@+id/iv_yaoyiyao"
                android:layout_width="24dp"
                android:layout_height="24dp"
                android:layout_alignParentLeft="true"
                android:layout_centerVertical="true"
                android:layout_marginLeft="12dp"
                android:src="@drawable/find_yaoyiyao" />
    
            <TextView
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_centerVertical="true"
                android:layout_marginLeft="20dp"
                android:layout_toRightOf="@id/iv_yaoyiyao"
                android:text="摇一摇"
                android:textColor="#353535"
                android:textSize="16sp" />
        </RelativeLayout>
    
        <RelativeLayout
            android:id="@+id/re_fujin"
            android:layout_width="match_parent"
            android:layout_height="48dp"
            android:layout_marginTop="20dp"
            android:background="@drawable/btn_list_item_bg"
            android:clickable="true"
            android:paddingLeft="12dp" >
    
            <ImageView
                android:id="@+id/iv_fujin"
                android:layout_width="24dp"
                android:layout_height="24dp"
                android:layout_alignParentLeft="true"
                android:layout_centerVertical="true"
                android:layout_marginLeft="12dp"
                android:src="@drawable/find_fujin" />
    
            <TextView
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_centerVertical="true"
                android:layout_marginLeft="20dp"
                android:layout_toRightOf="@id/iv_fujin"
                android:text="附近的人"
                android:textColor="#353535"
                android:textSize="16sp" />
    
            <View
                android:layout_width="match_parent"
                android:layout_height="0.1dp"
                android:layout_alignParentBottom="true"
                android:layout_marginRight="12dp"
                android:background="#dadada" />
        </RelativeLayout>
    
        <RelativeLayout
            android:id="@+id/re_piaoliuping"
            android:layout_width="match_parent"
            android:layout_height="48dp"
            android:background="@drawable/btn_list_item_bg"
            android:clickable="true"
            android:paddingLeft="12dp" >
    
            <ImageView
                android:id="@+id/iv_piaoliuping"
                android:layout_width="24dp"
                android:layout_height="24dp"
                android:layout_alignParentLeft="true"
                android:layout_centerVertical="true"
                android:layout_marginLeft="12dp"
                android:src="@drawable/find_piaoliuping" />
    
            <TextView
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_centerVertical="true"
                android:layout_marginLeft="20dp"
                android:layout_toRightOf="@id/iv_piaoliuping"
                android:text="漂流瓶"
                android:textColor="#353535"
                android:textSize="16sp" />
        </RelativeLayout>
    
        <RelativeLayout
            android:id="@+id/re_gouwu"
            android:layout_width="match_parent"
            android:layout_height="48dp"
            android:layout_marginTop="20dp"
            android:background="@drawable/btn_list_item_bg"
            android:clickable="true"
            android:paddingLeft="12dp" >
    
            <ImageView
                android:id="@+id/iv_gouwu"
                android:layout_width="24dp"
                android:layout_height="24dp"
                android:layout_alignParentLeft="true"
                android:layout_centerVertical="true"
                android:layout_marginLeft="12dp"
                android:src="@drawable/find_gouwu" />
    
            <TextView
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_centerVertical="true"
                android:layout_marginLeft="20dp"
                android:layout_toRightOf="@id/iv_gouwu"
                android:text="购物"
                android:textColor="#353535"
                android:textSize="16sp" />
    
            <View
                android:layout_width="match_parent"
                android:layout_height="0.1dp"
                android:layout_alignParentBottom="true"
                android:layout_marginRight="12dp"
                android:background="#dadada" />
        </RelativeLayout>
    
        <RelativeLayout
            android:id="@+id/re_youxi"
            android:layout_width="match_parent"
            android:layout_height="48dp"
            android:background="@drawable/btn_list_item_bg"
            android:clickable="true"
            android:paddingLeft="12dp" >
    
            <ImageView
                android:id="@+id/iv_youxi"
                android:layout_width="24dp"
                android:layout_height="24dp"
                android:layout_alignParentLeft="true"
                android:layout_centerVertical="true"
                android:layout_marginLeft="12dp"
                android:src="@drawable/find_youxi" />
    
            <TextView
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_centerVertical="true"
                android:layout_marginLeft="20dp"
                android:layout_toRightOf="@id/iv_youxi"
                android:text="游戏"
                android:textColor="#353535"
                android:textSize="16sp" />
        </RelativeLayout>
    </LinearLayout>
    FragmentProfile.java
    public class FragmentProfile extends Fragment {
    
        @Override
        public View onCreateView(LayoutInflater inflater, ViewGroup container,
                                 Bundle savedInstanceState) {
            return inflater.inflate(R.layout.fragment_profile, container, false);
        }
    }
    fragment_profile.xml
    <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
        android:orientation="vertical" android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:background="#ebebeb">
    
        <RelativeLayout
            android:id="@+id/re_myinfo"
            android:layout_width="match_parent"
            android:layout_height="80dp"
            android:layout_marginBottom="18dp"
            android:clickable="true"
            android:layout_marginTop="16dp"
            android:background="@drawable/btn_list_item_bg"
            android:paddingBottom="8dp"
            android:paddingTop="8dp" >
    
            <ImageView
                android:id="@+id/iv_avatar"
                android:layout_width="64dp"
                android:layout_height="64dp"
                android:layout_marginLeft="15dp"
                android:src="@drawable/default_useravatar" />
    
            <LinearLayout
                android:id="@+id/ll_name"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_marginLeft="16dp"
                android:layout_marginTop="12dp"
                android:layout_toRightOf="@id/iv_avatar"
                android:orientation="horizontal" >
    
                <TextView
                    android:id="@+id/tv_name"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:text="苏灿"
                    android:textColor="#353535"
                    android:textSize="16sp" />
    
                <ImageView
                    android:visibility="gone"
                    android:id="@+id/iv_sex"
                    android:layout_width="20dp"
                    android:layout_height="20dp"
                    android:layout_marginLeft="8dp"
                    android:src="@drawable/ic_sex_male" />
            </LinearLayout>
    
            <TextView
                android:id="@+id/tv_fxid"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_alignParentBottom="true"
                android:layout_marginBottom="10dp"
                android:layout_marginLeft="16dp"
                android:layout_toRightOf="@id/iv_avatar"
                android:text="微信号:"
                android:textColor="#AAAAAA"
                android:textSize="14sp" />
    
            <ImageView
                android:layout_marginRight="32dp"
                android:src="@drawable/a_5"
                android:layout_width="18dp"
                android:layout_height="18dp"
                android:layout_alignParentRight="true"
                android:layout_centerVertical="true"
    
                />
        </RelativeLayout>
    
        <RelativeLayout
            android:id="@+id/re_xiangce"
            android:layout_width="match_parent"
            android:layout_height="48dp"
            android:background="@drawable/btn_list_item_bg"
            android:clickable="true"
            android:paddingLeft="12dp" >
    
            <ImageView
                android:id="@+id/iv_xiangce"
                android:layout_width="24dp"
                android:layout_height="24dp"
                android:layout_alignParentLeft="true"
                android:layout_centerVertical="true"
                android:layout_marginLeft="12dp"
                android:src="@drawable/akb" />
    
            <TextView
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_centerVertical="true"
                android:layout_marginLeft="20dp"
                android:layout_toRightOf="@id/iv_xiangce"
                android:text="相册"
                android:textColor="#353535"
                android:textSize="16sp" />
    
            <View
                android:layout_width="match_parent"
                android:layout_height="0.1dp"
                android:layout_alignParentBottom="true"
                android:layout_marginRight="12dp"
                android:background="#dadada" />
        </RelativeLayout>
    
        <RelativeLayout
            android:id="@+id/re_shoucang"
            android:layout_width="match_parent"
            android:layout_height="48dp"
            android:background="@drawable/btn_list_item_bg"
            android:clickable="true"
            android:paddingLeft="12dp" >
    
            <ImageView
                android:id="@+id/iv_shoucang"
                android:layout_width="24dp"
                android:layout_height="24dp"
                android:layout_alignParentLeft="true"
                android:layout_centerVertical="true"
                android:layout_marginLeft="12dp"
                android:src="@drawable/ake" />
    
            <TextView
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_centerVertical="true"
                android:layout_marginLeft="20dp"
                android:layout_toRightOf="@id/iv_shoucang"
                android:text="收藏"
                android:textColor="#353535"
                android:textSize="16sp" />
        </RelativeLayout>
        <RelativeLayout
            android:layout_marginTop="20dp"
            android:id="@+id/re_money_bag"
            android:layout_width="match_parent"
            android:layout_height="48dp"
            android:background="@drawable/btn_list_item_bg"
            android:clickable="true"
            android:paddingLeft="12dp" >
    
            <ImageView
                android:id="@+id/iv_money_bag"
                android:layout_width="24dp"
                android:layout_height="24dp"
                android:layout_alignParentLeft="true"
                android:layout_centerVertical="true"
                android:layout_marginLeft="12dp"
                android:src="@drawable/akc" />
    
            <TextView
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_centerVertical="true"
                android:layout_marginLeft="20dp"
                android:layout_toRightOf="@id/iv_money_bag"
                android:text="钱包"
                android:textColor="#353535"
                android:textSize="16sp" />
    
            <View
                android:layout_width="match_parent"
                android:layout_height="0.1dp"
                android:layout_alignParentBottom="true"
                android:layout_marginRight="12dp"
                android:background="#dadada" />
        </RelativeLayout>
    
        <RelativeLayout
            android:id="@+id/re_card_bag"
            android:layout_width="match_parent"
            android:layout_height="48dp"
            android:background="@drawable/btn_list_item_bg"
            android:clickable="true"
            android:paddingLeft="12dp" >
    
            <ImageView
                android:id="@+id/iv_card_bag"
                android:layout_width="24dp"
                android:layout_height="24dp"
                android:layout_alignParentLeft="true"
                android:layout_centerVertical="true"
                android:layout_marginLeft="12dp"
                android:src="@drawable/akd" />
    
            <TextView
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_centerVertical="true"
                android:layout_marginLeft="20dp"
                android:layout_toRightOf="@id/iv_card_bag"
                android:text="卡包"
                android:textColor="#353535"
                android:textSize="16sp" />
        </RelativeLayout>
        <RelativeLayout
            android:layout_marginTop="20dp"
            android:id="@+id/re_setting"
            android:layout_width="match_parent"
            android:layout_height="48dp"
            android:background="@drawable/btn_list_item_bg"
            android:clickable="true"
            android:paddingLeft="12dp" >
    
            <ImageView
                android:id="@+id/iv_setting"
                android:layout_width="24dp"
                android:layout_height="24dp"
                android:layout_alignParentLeft="true"
                android:layout_centerVertical="true"
                android:layout_marginLeft="12dp"
                android:src="@drawable/akf" />
    
            <TextView
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_centerVertical="true"
                android:layout_marginLeft="20dp"
                android:layout_toRightOf="@id/iv_setting"
                android:text="设置"
                android:textColor="#353535"
                android:textSize="16sp" />
        </RelativeLayout>
    
    
    </LinearLayout>

    UPDATE:

    增加设置和个人资料,以及popupwindow的界面

    public class FragmentProfile extends Fragment {
    
        @Override
        public View onCreateView(LayoutInflater inflater, ViewGroup container,
                                 Bundle savedInstanceState) {
            return inflater.inflate(R.layout.fragment_profile, container, false);
        }
    
        @Override
        public void onActivityCreated(Bundle savedInstanceState) {
            super.onActivityCreated(savedInstanceState);
            RelativeLayout re_myinfo = (RelativeLayout) getView().findViewById(
                    R.id.re_myinfo);
            re_myinfo.setOnClickListener(new View.OnClickListener() {
    
                @Override
                public void onClick(View v) {
                    startActivity(new Intent(getActivity(),
                            MyUserInfoActivity.class));
                }
    
            });
    
            RelativeLayout re_setting = (RelativeLayout) getView().findViewById(
                    R.id.re_setting);
            re_setting.setOnClickListener(new View.OnClickListener() {
    
                @Override
                public void onClick(View v) {
                    startActivity(new Intent(getActivity(), SettingActivity.class));
                }
    
            });
        }
    }
    public class MyUserInfoActivity extends Activity {
    
        @Override
        public void onCreate(Bundle savedInstanceState) {
            super.onCreate(savedInstanceState);
            setContentView(R.layout.activity_myinfo);
        }
    }
    <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:background="#ebebeb"
        android:orientation="vertical" >
        <RelativeLayout
            android:id="@+id/title"
            android:layout_width="match_parent"
            android:layout_height="@dimen/height_top_bar"
            android:background="@color/common_top_bar_blue" >
    
            <ImageView
                android:id="@+id/iv_back"
                android:layout_width="40dp"
                android:layout_height="match_parent"
                android:layout_alignParentLeft="true"
                android:layout_centerVertical="true"
                android:onClick="back"
                android:paddingBottom="5dp"
                android:paddingLeft="5dp"
                android:paddingRight="5dp"
                android:paddingTop="5dp"
                android:scaleType="centerInside"
                android:src="@drawable/top_bar_back" />
    
            <View
                android:id="@+id/view_temp"
                android:layout_width="1dp"
                android:layout_height="match_parent"
                android:layout_marginBottom="8dp"
                android:layout_marginTop="8dp"
                android:layout_toRightOf="@id/iv_back"
                android:background="#14191A" />
    
            <TextView
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_centerVertical="true"
                android:layout_marginLeft="10dp"
                android:layout_toRightOf="@id/view_temp"
                android:text="个人信息"
                android:textColor="#ffffff"
                android:textSize="18sp" />
    
    
        </RelativeLayout>
        <RelativeLayout
            android:id="@+id/re_avatar"
            android:layout_width="match_parent"
            android:layout_height="80dp"
            android:layout_marginTop="20dp"
            android:background="@drawable/btn_list_item_bg"
            android:clickable="true" >
    
            <ImageView
                android:id="@+id/iv_avatar"
                android:layout_width="64dp"
                android:layout_height="64dp"
                android:layout_alignParentRight="true"
                android:layout_centerVertical="true"
                android:layout_marginRight="12dp"
                android:src="@drawable/default_useravatar" />
    
            <TextView
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_centerVertical="true"
                android:layout_marginLeft="20dp"
                android:text="头像"
                android:textColor="#353535"
                android:textSize="16sp" />
    
            <View
                android:layout_width="match_parent"
                android:layout_height="0.1dp"
                android:layout_alignParentBottom="true"
                android:layout_marginLeft="12dp"
                android:layout_marginRight="12dp"
                android:background="#dadada" />
        </RelativeLayout>
    
        <RelativeLayout
            android:id="@+id/re_name"
            android:layout_width="match_parent"
            android:layout_height="48dp"
            android:background="@drawable/btn_list_item_bg"
            android:clickable="true" >
    
            <TextView
                android:id="@+id/tv_temp_name"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_alignParentLeft="true"
                android:layout_centerVertical="true"
                android:layout_marginLeft="20dp"
                android:text="昵称"
                android:textColor="#353535"
                android:textSize="16sp" />
    
            <TextView
                android:id="@+id/tv_name"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:layout_alignParentRight="true"
                android:layout_centerVertical="true"
                android:layout_marginRight="20dp"
                android:layout_toRightOf="@id/tv_temp_name"
                android:ellipsize="end"
                android:gravity="right"
                android:singleLine="true"
                android:text="苏灿"
                android:textColor="#AAAAAA"
                android:textSize="14sp" />
    
            <View
                android:layout_width="match_parent"
                android:layout_height="0.1dp"
                android:layout_alignParentBottom="true"
                android:layout_marginLeft="12dp"
                android:layout_marginRight="12dp"
                android:background="#dadada" />
        </RelativeLayout>
    
        <RelativeLayout
            android:id="@+id/re_fxid"
            android:layout_width="match_parent"
            android:layout_height="48dp"
            android:background="@drawable/btn_list_item_bg"
            android:clickable="true" >
    
            <TextView
                android:id="@+id/tv_temp_fxid"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_alignParentLeft="true"
                android:layout_centerVertical="true"
                android:layout_marginLeft="20dp"
                android:text="微信号"
                android:textColor="#353535"
                android:textSize="16sp" />
    
            <TextView
                android:id="@+id/tv_fxid"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:layout_alignParentRight="true"
                android:layout_centerVertical="true"
                android:layout_marginRight="20dp"
                android:layout_toRightOf="@id/tv_temp_fxid"
                android:ellipsize="end"
                android:gravity="right"
                android:singleLine="true"
                android:text="tingyi_tech"
                android:textColor="#AAAAAA"
                android:textSize="14sp" />
    
            <View
                android:layout_width="match_parent"
                android:layout_height="0.1dp"
                android:layout_alignParentBottom="true"
                android:layout_marginLeft="12dp"
                android:layout_marginRight="12dp"
                android:background="#dadada" />
        </RelativeLayout>
    
        <RelativeLayout
            android:id="@+id/re_erweima"
            android:layout_width="match_parent"
            android:layout_height="48dp"
            android:background="@drawable/btn_list_item_bg"
            android:clickable="true" >
    
            <TextView
                android:id="@+id/tv_temp_erweima"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_alignParentLeft="true"
                android:layout_centerVertical="true"
                android:layout_marginLeft="20dp"
                android:text="二维码名片"
                android:textColor="#353535"
                android:textSize="16sp" />
    
            <ImageView
                android:layout_width="18dp"
                android:layout_height="18dp"
                android:layout_alignParentRight="true"
                android:layout_centerVertical="true"
                android:layout_marginRight="20dp"
                android:src="@drawable/a_5" />
    
            <View
                android:layout_width="match_parent"
                android:layout_height="0.1dp"
                android:layout_alignParentBottom="true"
                android:layout_marginLeft="12dp"
                android:layout_marginRight="12dp"
                android:background="#dadada" />
        </RelativeLayout>
    
        <RelativeLayout
            android:id="@+id/re_address"
            android:layout_width="match_parent"
            android:layout_height="48dp"
            android:background="@drawable/btn_list_item_bg"
            android:clickable="true" >
    
            <TextView
                android:id="@+id/tv_temp_address"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_alignParentLeft="true"
                android:layout_centerVertical="true"
                android:layout_marginLeft="20dp"
                android:text="我的地址"
                android:textColor="#353535"
                android:textSize="16sp" />
        </RelativeLayout>
    
        <RelativeLayout
            android:id="@+id/re_sex"
            android:layout_width="match_parent"
            android:layout_height="48dp"
            android:layout_marginTop="20dp"
            android:background="@drawable/btn_list_item_bg"
            android:clickable="true" >
    
            <TextView
                android:id="@+id/tv_temp_sex"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_alignParentLeft="true"
                android:layout_centerVertical="true"
                android:layout_marginLeft="20dp"
                android:text="性别"
                android:textColor="#353535"
                android:textSize="16sp" />
    
            <TextView
                android:id="@+id/tv_sex"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:layout_alignParentRight="true"
                android:layout_centerVertical="true"
                android:layout_marginRight="20dp"
                android:layout_toRightOf="@id/tv_temp_sex"
                android:ellipsize="end"
                android:gravity="right"
                android:singleLine="true"
                android:text="男"
                android:textColor="#AAAAAA"
                android:textSize="14sp" />
    
            <View
                android:layout_width="match_parent"
                android:layout_height="0.1dp"
                android:layout_alignParentBottom="true"
                android:layout_marginLeft="12dp"
                android:layout_marginRight="12dp"
                android:background="#dadada" />
        </RelativeLayout>
        <RelativeLayout
            android:id="@+id/re_region"
            android:layout_width="match_parent"
            android:layout_height="48dp"
    
            android:background="@drawable/btn_list_item_bg"
            android:clickable="true" >
    
            <TextView
                android:id="@+id/tv_temp_region"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_alignParentLeft="true"
                android:layout_centerVertical="true"
                android:layout_marginLeft="20dp"
                android:text="地区"
                android:textColor="#353535"
                android:textSize="16sp" />
    
            <TextView
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:layout_alignParentRight="true"
                android:layout_centerVertical="true"
                android:layout_marginRight="20dp"
                android:layout_toRightOf="@id/tv_temp_region"
                android:ellipsize="end"
                android:gravity="right"
                android:singleLine="true"
                android:text="安徽合肥"
                android:textColor="#AAAAAA"
                android:textSize="14sp" />
    
            <View
                android:layout_width="match_parent"
                android:layout_height="0.1dp"
                android:layout_alignParentBottom="true"
                android:layout_marginLeft="12dp"
                android:layout_marginRight="12dp"
                android:background="#dadada" />
        </RelativeLayout>
        <RelativeLayout
            android:id="@+id/re_sign"
            android:layout_width="match_parent"
            android:layout_height="48dp"
    
            android:background="@drawable/btn_list_item_bg"
            android:clickable="true" >
    
            <TextView
                android:id="@+id/tv_temp_sign"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_alignParentLeft="true"
                android:layout_centerVertical="true"
                android:layout_marginLeft="20dp"
                android:text="个性签名"
                android:textColor="#353535"
                android:textSize="16sp" />
    
            <TextView
                android:id="@+id/tv_sign"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:layout_alignParentRight="true"
                android:layout_centerVertical="true"
                android:layout_marginRight="20dp"
                android:layout_toRightOf="@id/tv_temp_sign"
                android:ellipsize="end"
                android:gravity="right"
                android:singleLine="true"
                android:text="志存高远,脚踏实地"
                android:textColor="#AAAAAA"
                android:textSize="14sp" />
    
    
        </RelativeLayout>
    </LinearLayout>
    public class SettingActivity extends Activity implements View.OnClickListener {
    
        /**
         * 设置新消息通知布局
         */
        private RelativeLayout rl_switch_notification;
        /**
         * 设置声音布局
         */
        private RelativeLayout rl_switch_sound;
        /**
         * 设置震动布局
         */
        private RelativeLayout rl_switch_vibrate;
        /**
         * 设置扬声器布局
         */
        private RelativeLayout rl_switch_speaker;
    
        /**
         * 打开新消息通知imageView
         */
        private ImageView iv_switch_open_notification;
        /**
         * 关闭新消息通知imageview
         */
        private ImageView iv_switch_close_notification;
        /**
         * 打开声音提示imageview
         */
        private ImageView iv_switch_open_sound;
        /**
         * 关闭声音提示imageview
         */
        private ImageView iv_switch_close_sound;
        /**
         * 打开消息震动提示
         */
        private ImageView iv_switch_open_vibrate;
        /**
         * 关闭消息震动提示
         */
        private ImageView iv_switch_close_vibrate;
        /**
         * 打开扬声器播放语音
         */
        private ImageView iv_switch_open_speaker;
        /**
         * 关闭扬声器播放语音
         */
        private ImageView iv_switch_close_speaker;
        /**
         * 退出按钮
         */
        private Button logoutBtn;
    
        @Override
        protected void onCreate(Bundle savedInstanceState) {
            super.onCreate(savedInstanceState);
            setContentView(R.layout.activity_setting);
    
            if(savedInstanceState != null)
                return;
    
            rl_switch_notification = (RelativeLayout) this.findViewById(R.id.rl_switch_notification);
            rl_switch_sound = (RelativeLayout) this.findViewById(R.id.rl_switch_sound);
            rl_switch_vibrate = (RelativeLayout) this.findViewById(R.id.rl_switch_vibrate);
            rl_switch_speaker = (RelativeLayout) this.findViewById(R.id.rl_switch_speaker);
    
            iv_switch_open_notification = (ImageView) this.findViewById(R.id.iv_switch_open_notification);
            iv_switch_close_notification = (ImageView) this.findViewById(R.id.iv_switch_close_notification);
            iv_switch_open_sound = (ImageView) this.findViewById(R.id.iv_switch_open_sound);
            iv_switch_close_sound = (ImageView) this.findViewById(R.id.iv_switch_close_sound);
            iv_switch_open_vibrate = (ImageView) this.findViewById(R.id.iv_switch_open_vibrate);
            iv_switch_close_vibrate = (ImageView) this.findViewById(R.id.iv_switch_close_vibrate);
            iv_switch_open_speaker = (ImageView) this.findViewById(R.id.iv_switch_open_speaker);
            iv_switch_close_speaker = (ImageView) this.findViewById(R.id.iv_switch_close_speaker);
            logoutBtn = (Button) this.findViewById(R.id.btn_logout);
            rl_switch_notification.setOnClickListener(this);
            rl_switch_sound.setOnClickListener(this);
            rl_switch_vibrate.setOnClickListener(this);
            rl_switch_speaker.setOnClickListener(this);
            logoutBtn.setOnClickListener(this);
        }
    
        @Override
        public void onClick(View v) {
            switch (v.getId()) {
                case R.id.rl_switch_notification:
                    if (iv_switch_open_notification.getVisibility() == View.VISIBLE) {
                        iv_switch_open_notification.setVisibility(View.INVISIBLE);
                        iv_switch_close_notification.setVisibility(View.VISIBLE);
                        rl_switch_sound.setVisibility(View.GONE);
                        rl_switch_vibrate.setVisibility(View.GONE);
                    } else {
                        iv_switch_open_notification.setVisibility(View.VISIBLE);
                        iv_switch_close_notification.setVisibility(View.INVISIBLE);
                        rl_switch_sound.setVisibility(View.VISIBLE);
                        rl_switch_vibrate.setVisibility(View.VISIBLE);
                    }
                    break;
                case R.id.rl_switch_sound:
                    if (iv_switch_open_sound.getVisibility() == View.VISIBLE) {
                        iv_switch_open_sound.setVisibility(View.INVISIBLE);
                        iv_switch_close_sound.setVisibility(View.VISIBLE);
    
                    } else {
                        iv_switch_open_sound.setVisibility(View.VISIBLE);
                        iv_switch_close_sound.setVisibility(View.INVISIBLE);
    
                    }
                    break;
                case R.id.rl_switch_vibrate:
                    if (iv_switch_open_vibrate.getVisibility() == View.VISIBLE) {
                        iv_switch_open_vibrate.setVisibility(View.INVISIBLE);
                        iv_switch_close_vibrate.setVisibility(View.VISIBLE);
    
                    } else {
                        iv_switch_open_vibrate.setVisibility(View.VISIBLE);
                        iv_switch_close_vibrate.setVisibility(View.INVISIBLE);
    
                    }
                    break;
                case R.id.rl_switch_speaker:
                    if (iv_switch_open_speaker.getVisibility() == View.VISIBLE) {
                        iv_switch_open_speaker.setVisibility(View.INVISIBLE);
                        iv_switch_close_speaker.setVisibility(View.VISIBLE);
    
                    } else {
                        iv_switch_open_speaker.setVisibility(View.VISIBLE);
                        iv_switch_close_speaker.setVisibility(View.INVISIBLE);
    
                    }
                    break;
                case R.id.btn_logout: //退出登陆
                    break;
    
                default:
                    break;
            }
    
        }
    
        @Override
        public void onSaveInstanceState(Bundle outState) {
    
            super.onSaveInstanceState(outState);
    
        }
    
        public void back(View view){
    
            finish();
        }
    }
    <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:background="#EBEBEB"
        android:orientation="vertical" >
    
        <RelativeLayout
            android:id="@+id/title"
            android:layout_width="match_parent"
            android:layout_height="@dimen/height_top_bar"
            android:background="@color/common_top_bar_blue" >
    
            <ImageView
                android:id="@+id/iv_back"
                android:layout_width="40dp"
                android:layout_height="match_parent"
                android:layout_alignParentLeft="true"
                android:layout_centerVertical="true"
                android:onClick="back"
                android:paddingBottom="5dp"
                android:paddingLeft="5dp"
                android:paddingRight="5dp"
                android:paddingTop="5dp"
                android:scaleType="centerInside"
                android:src="@drawable/top_bar_back" />
    
            <View
                android:id="@+id/view_temp"
                android:layout_width="1dp"
                android:layout_height="match_parent"
                android:layout_marginBottom="8dp"
                android:layout_marginTop="8dp"
                android:layout_toRightOf="@id/iv_back"
                android:background="#14191A" />
    
            <TextView
                android:id="@+id/tv_title"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_centerVertical="true"
                android:layout_marginLeft="10dp"
                android:layout_toRightOf="@id/view_temp"
                android:text="设置"
                android:textColor="#ffffff"
                android:textSize="18sp" />
        </RelativeLayout>
    
        <ScrollView
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:fadingEdge="none" >
    
            <LinearLayout
                android:layout_width="match_parent"
                android:layout_height="match_parent"
                android:orientation="vertical" >
    
                <LinearLayout
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:orientation="vertical" >
    
                    <RelativeLayout
                        android:id="@+id/rl_switch_notification"
                        android:layout_width="match_parent"
                        android:layout_height="50dip"
                        android:layout_marginTop="20dp"
                        android:background="@drawable/btn_list_item_bg"
                        android:clickable="true"
                        android:padding="10dip" >
    
                        <TextView
                            android:layout_width="wrap_content"
                            android:layout_height="wrap_content"
                            android:layout_centerVertical="true"
                            android:paddingLeft="10dip"
                            android:text="接收新消息通知"
                            android:textColor="#353535"
                            android:textSize="16sp" />
    
                        <ImageView
                            android:id="@+id/iv_switch_open_notification"
                            android:layout_width="70dp"
                            android:layout_height="22dp"
                            android:layout_alignParentRight="true"
                            android:layout_centerVertical="true"
                            android:background="@drawable/open_icon"
                            android:visibility="visible" />
    
                        <ImageView
                            android:id="@+id/iv_switch_close_notification"
                            android:layout_width="70dp"
                            android:layout_height="22dp"
                            android:layout_alignParentRight="true"
                            android:layout_centerVertical="true"
                            android:background="@drawable/close_icon"
                            android:visibility="invisible" />
                    </RelativeLayout>
    
                    <View
                        android:layout_width="match_parent"
                        android:layout_height="0.1dp"
                        android:background="#dadada" />
    
                    <RelativeLayout
                        android:id="@+id/rl_switch_sound"
                        android:layout_width="match_parent"
                        android:layout_height="50dip"
                        android:background="@drawable/btn_list_item_bg"
                        android:clickable="true"
                        android:padding="10dip" >
    
                        <TextView
                            android:layout_width="wrap_content"
                            android:layout_height="wrap_content"
                            android:layout_centerVertical="true"
                            android:paddingLeft="10dip"
                            android:text="声音"
                            android:textColor="#353535"
                            android:textSize="16sp" />
    
                        <ImageView
                            android:id="@+id/iv_switch_open_sound"
                            android:layout_width="70dp"
                            android:layout_height="22dp"
                            android:layout_alignParentRight="true"
                            android:layout_centerVertical="true"
                            android:background="@drawable/open_icon"
                            android:visibility="visible" />
    
                        <ImageView
                            android:id="@+id/iv_switch_close_sound"
                            android:layout_width="70dp"
                            android:layout_height="22dp"
                            android:layout_alignParentRight="true"
                            android:layout_centerVertical="true"
                            android:background="@drawable/close_icon"
                            android:visibility="invisible" />
                    </RelativeLayout>
    
                    <View
                        android:layout_width="match_parent"
                        android:layout_height="0.1dp"
                        android:background="#dadada" />
    
                    <RelativeLayout
                        android:id="@+id/rl_switch_vibrate"
                        android:layout_width="match_parent"
                        android:layout_height="50dip"
                        android:background="@drawable/btn_list_item_bg"
                        android:clickable="true"
                        android:padding="10dip" >
    
                        <TextView
                            android:layout_width="wrap_content"
                            android:layout_height="wrap_content"
                            android:layout_centerVertical="true"
                            android:paddingLeft="10dip"
                            android:text="震动"
                            android:textColor="#353535"
                            android:textSize="16sp" />
    
                        <ImageView
                            android:id="@+id/iv_switch_open_vibrate"
                            android:layout_width="70dp"
                            android:layout_height="22dp"
                            android:layout_alignParentRight="true"
                            android:layout_centerVertical="true"
                            android:background="@drawable/open_icon"
                            android:visibility="visible" />
    
                        <ImageView
                            android:id="@+id/iv_switch_close_vibrate"
                            android:layout_width="70dp"
                            android:layout_height="22dp"
                            android:layout_alignParentRight="true"
                            android:layout_centerVertical="true"
                            android:background="@drawable/close_icon"
                            android:visibility="invisible" />
                    </RelativeLayout>
    
                    <RelativeLayout
                        android:id="@+id/rl_switch_speaker"
                        android:layout_width="match_parent"
                        android:layout_height="50dip"
                        android:layout_marginTop="20dp"
                        android:background="@drawable/btn_list_item_bg"
                        android:clickable="true"
                        android:padding="10dip" >
    
                        <TextView
                            android:layout_width="wrap_content"
                            android:layout_height="wrap_content"
                            android:layout_centerVertical="true"
                            android:paddingLeft="10dip"
                            android:text="使用扬声器播放语音"
                            android:textColor="#353535"
                            android:textSize="16sp" />
    
                        <ImageView
                            android:id="@+id/iv_switch_open_speaker"
                            android:layout_width="70dp"
                            android:layout_height="22dp"
                            android:layout_alignParentRight="true"
                            android:layout_centerVertical="true"
                            android:background="@drawable/open_icon"
                            android:visibility="visible" />
    
                        <ImageView
                            android:id="@+id/iv_switch_close_speaker"
                            android:layout_width="70dp"
                            android:layout_height="22dp"
                            android:layout_alignParentRight="true"
                            android:layout_centerVertical="true"
                            android:background="@drawable/close_icon"
                            android:visibility="invisible" />
                    </RelativeLayout>
                </LinearLayout>
    
    
    
                <Button
                    android:gravity="center_vertical|left"
                    android:paddingLeft="10dip"
                    android:id="@+id/btn_logout"
                    android:layout_width="match_parent"
                    android:layout_height="48dp"
                    android:layout_marginTop="40dp"
                    android:background="@drawable/btn_list_item_bg"
                    android:text="@string/button_logout"
                    android:textColor="#353535"
                    android:textSize="16sp" />
            </LinearLayout>
        </ScrollView>
    
    </LinearLayout>

    popupwindow:

    public class MainActivity extends AppCompatActivity {
        private ImageView iv_add;
        private ImageView iv_search;
        private Fragment[] fragments;
        public FragmentCoversation homefragment;
        private FragmentFriends contactlistfragment;
        private FragmentFind findfragment;
        private FragmentProfile profilefragment;
    
        private ImageView[] imagebuttons;
        private TextView[] textviews;
        private int index;
        // 当前fragment的index
        private int currentTabIndex;
    
    
        @Override
        protected void onCreate(Bundle savedInstanceState) {
            super.onCreate(savedInstanceState);
            setContentView(R.layout.activity_main);
    
            iv_add = (ImageView) this.findViewById(R.id.iv_add);
            iv_search = (ImageView) this.findViewById(R.id.iv_search);
            initView();
    
            iv_add = (ImageView) this.findViewById(R.id.iv_add);
            iv_search = (ImageView) this.findViewById(R.id.iv_search);
            iv_add.setOnClickListener(new View.OnClickListener() {
    
                @Override
                public void onClick(View v) {
                    AddPopWindow addPopWindow = new AddPopWindow(MainActivity.this);
                    addPopWindow.showPopupWindow(iv_add);
                }
    
            });
            iv_search.setOnClickListener(new View.OnClickListener() {
    
                @Override
                public void onClick(View v) {
    
                }
    
            });
        }
    
        private void initView() {
    
            homefragment = new FragmentCoversation();
            contactlistfragment = new FragmentFriends();
            findfragment = new FragmentFind();
            profilefragment = new FragmentProfile();
            fragments = new Fragment[] { homefragment, contactlistfragment,
                    findfragment, profilefragment };
            imagebuttons = new ImageView[4];
            imagebuttons[0] = (ImageView) findViewById(R.id.ib_weixin);
            imagebuttons[1] = (ImageView) findViewById(R.id.ib_contact_list);
            imagebuttons[2] = (ImageView) findViewById(R.id.ib_find);
            imagebuttons[3] = (ImageView) findViewById(R.id.ib_profile);
    
            imagebuttons[0].setSelected(true);
            textviews = new TextView[4];
            textviews[0] = (TextView) findViewById(R.id.tv_weixin);
            textviews[1] = (TextView) findViewById(R.id.tv_contact_list);
            textviews[2] = (TextView) findViewById(R.id.tv_find);
            textviews[3] = (TextView) findViewById(R.id.tv_profile);
            textviews[0].setTextColor(0xFF45C01A);
            // 添加显示第一个fragment
            getSupportFragmentManager().beginTransaction()
                    .add(R.id.fragment_container, homefragment)
                    .add(R.id.fragment_container, contactlistfragment)
                    .add(R.id.fragment_container, profilefragment)
                    .add(R.id.fragment_container, findfragment)
                    .hide(contactlistfragment).hide(profilefragment)
                    .hide(findfragment).show(homefragment).commit();
    
    
        }
    
        public void onTabClicked(View view) {
            switch (view.getId()) {
                case R.id.re_weixin:
                    index = 0;
                    break;
                case R.id.re_contact_list:
                    index = 1;
                    break;
                case R.id.re_find:
                    index = 2;
                    break;
                case R.id.re_profile:
                    index = 3;
                    break;
    
            }
    
            if (currentTabIndex != index) {
                FragmentTransaction trx = getSupportFragmentManager()
                        .beginTransaction();
                trx.hide(fragments[currentTabIndex]);
                if (!fragments[index].isAdded()) {
                    trx.add(R.id.fragment_container, fragments[index]);
                }
                trx.show(fragments[index]).commit();
            }
            imagebuttons[currentTabIndex].setSelected(false);
            // 把当前tab设为选中状态
            imagebuttons[index].setSelected(true);
            textviews[currentTabIndex].setTextColor(0xFF999999);
            textviews[index].setTextColor(0xFF45C01A);
            currentTabIndex = index;
        }
    
    }
    public class AddPopWindow extends PopupWindow {
        private View conentView;
    
    
        @SuppressLint("InflateParams")
        public AddPopWindow(final Activity context) {
            LayoutInflater inflater = (LayoutInflater) context
                    .getSystemService(Context.LAYOUT_INFLATER_SERVICE);
            conentView = inflater.inflate(R.layout.popupwindow_add, null);
    
            // 设置SelectPicPopupWindow的View
            this.setContentView(conentView);
            // 设置SelectPicPopupWindow弹出窗体的宽
            this.setWidth(ViewGroup.LayoutParams.WRAP_CONTENT);
            // 设置SelectPicPopupWindow弹出窗体的高
            this.setHeight(ViewGroup.LayoutParams.WRAP_CONTENT);
            // 设置SelectPicPopupWindow弹出窗体可点击
            this.setFocusable(true);
            this.setOutsideTouchable(true);
            // 刷新状态
            this.update();
            // 实例化一个ColorDrawable颜色为半透明
            ColorDrawable dw = new ColorDrawable(0000000000);
            // 点back键和其他地方使其消失,设置了这个才能触发OnDismisslistener ,设置其他控件变化等操作
            this.setBackgroundDrawable(dw);
    
            // 设置SelectPicPopupWindow弹出窗体动画效果
            this.setAnimationStyle(R.style.AnimationPreview);
        }
    
        /**
         * 显示popupWindow
         *
         * @param parent
         */
        public void showPopupWindow(View parent) {
            if (!this.isShowing()) {
                // 以下拉方式显示popupwindow
                this.showAsDropDown(parent, 0, 0);
            } else {
                this.dismiss();
            }
        }
    }
    <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:background="#fff"
        android:orientation="vertical" >
    
        <LinearLayout
            android:layout_width="212dp"
            android:paddingRight="12dp"
            android:layout_height="wrap_content"
            android:orientation="vertical" >
    
            <RelativeLayout
                android:id="@+id/re_chatroom"
                android:layout_width="match_parent"
                android:layout_height="48dp"
                android:background="#22292C" >
    
                <ImageView
                    android:layout_width="30dp"
                    android:layout_height="30dp"
                    android:layout_alignParentLeft="true"
                    android:layout_centerVertical="true"
                    android:layout_marginLeft="13dp"
                    android:src="@drawable/popwindow_add_icon1" />
    
                <TextView
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:layout_centerVertical="true"
                    android:layout_marginLeft="63dp"
                    android:text="发起群聊"
                    android:textColor="#fff"
                    android:textSize="16sp" />
            </RelativeLayout>
    
            <View
                android:layout_width="match_parent"
                android:layout_height="0.1dp"
                android:background="#191B1C" />
    
            <RelativeLayout
                android:id="@+id/re_addfriends"
                android:layout_width="match_parent"
                android:layout_height="48dp"
                android:background="#22292C" >
    
                <ImageView
                    android:layout_width="30dp"
                    android:layout_height="30dp"
                    android:layout_alignParentLeft="true"
                    android:layout_centerVertical="true"
                    android:layout_marginLeft="13dp"
                    android:src="@drawable/popwindow_add_icon2" />
    
                <TextView
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:layout_centerVertical="true"
                    android:layout_marginLeft="63dp"
                    android:text="添加朋友"
                    android:textColor="#fff"
                    android:textSize="16sp" />
            </RelativeLayout>
    
            <View
                android:layout_width="match_parent"
                android:layout_height="0.1dp"
                android:background="#191B1C" />
    
            <RelativeLayout
                android:id="@+id/re_saoyisao"
                android:layout_width="match_parent"
                android:layout_height="48dp"
                android:background="#22292C" >
    
                <ImageView
                    android:layout_width="30dp"
                    android:layout_height="30dp"
                    android:layout_alignParentLeft="true"
                    android:layout_centerVertical="true"
                    android:layout_marginLeft="13dp"
                    android:src="@drawable/popwindow_add_icon3" />
    
                <TextView
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:layout_centerVertical="true"
                    android:layout_marginLeft="63dp"
                    android:text="扫一扫"
                    android:textColor="#fff"
                    android:textSize="16sp" />
            </RelativeLayout>
    
            <View
                android:layout_width="match_parent"
                android:layout_height="0.1dp"
                android:background="#191B1C" />
    
            <RelativeLayout
                android:id="@+id/re_help"
                android:layout_width="match_parent"
                android:layout_height="48dp"
                android:background="#22292C" >
    
                <ImageView
                    android:layout_width="30dp"
                    android:layout_height="30dp"
                    android:layout_alignParentLeft="true"
                    android:layout_centerVertical="true"
                    android:layout_marginLeft="13dp"
                    android:src="@drawable/popwindow_add_icon4" />
    
                <TextView
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:layout_centerVertical="true"
                    android:layout_marginLeft="63dp"
                    android:text="帮助与反馈"
                    android:textColor="#fff"
                    android:textSize="16sp" />
            </RelativeLayout>
        </LinearLayout>
    
    </LinearLayout>

    animation:

    <style name="AnimationPreview">
            <item name="android:windowEnterAnimation">@anim/fade_in</item>
            <item name="android:windowExitAnimation">@anim/fade_out</item>
        </style>

    fade_in

    <alpha xmlns:android="http://schemas.android.com/apk/res/android"
        android:interpolator="@android:anim/accelerate_interpolator"
        android:fromAlpha="0.0" android:toAlpha="1.0"
        android:duration="300" />

    fade_out

    <alpha xmlns:android="http://schemas.android.com/apk/res/android"
        android:interpolator="@android:anim/accelerate_interpolator"
        android:fromAlpha="1.0" android:toAlpha="0.0"
        android:duration="300" />

    最后注册一下

  • 相关阅读:
    MongoDB数据类型
    杭电1257
    杭电1716
    杭电1997
    杭电1492
    杭电1208
    杭电1290
    杭电1087
    杭电1568
    杭电1398
  • 原文地址:https://www.cnblogs.com/qlky/p/5489607.html
Copyright © 2020-2023  润新知