fragment_me.xml MeFragment.java ...
fragment_me.xml
<?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools" xmlns:app="http://schemas.android.com/apk/res-auto" android:orientation="vertical" android:background="@color/app_bg" android:layout_width="match_parent" android:layout_height="match_parent"> <ScrollView android:layout_width="match_parent" android:layout_height="match_parent" android:background="@color/app_bg"> <LinearLayout android:layout_width="match_parent" android:layout_height="wrap_content" android:orientation="vertical"> <RelativeLayout android:id="@+id/me_login_layout" android:layout_width="match_parent" android:layout_height="@dimen/me_login_layout_height" android:paddingLeft="@dimen/me_login_layout_paddingLeft" android:background="@mipmap/my_login_bg" android:visibility="gone"> <com.facebook.drawee.view.SimpleDraweeView android:id="@+id/me_login_iv_head" android:layout_width="@dimen/me_login_head_width" android:layout_height="@dimen/me_login_head_height" android:layout_marginEnd="@dimen/me_login_head_marginEnd" android:layout_centerVertical="true" android:scaleType="fitXY" app:placeholderImage="@mipmap/user_head"/> <LinearLayout android:id="@+id/me_login_profile_layout" android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_centerVertical="true" android:layout_toRightOf="@+id/me_login_iv_head" android:orientation="vertical"> <RelativeLayout android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_marginStart="@dimen/me_login_profile_layout_marginStart"> <TextView android:id="@+id/me_login_tv_username" android:layout_width="wrap_content" android:layout_height="wrap_content" tools:text="布拉拉" android:singleLine="true" android:ellipsize="end" android:textColor="@color/grad" android:textSize="@dimen/me_login_username_size"/> <ImageView android:id="@+id/me_login_iv_level" android:layout_width="@dimen/me_login_level_width" android:layout_height="@dimen/me_login_level_height" android:layout_marginStart="@dimen/me_login_level_marginStart" android:layout_toRightOf="@+id/me_login_tv_username" android:src="@mipmap/level_0"/> </RelativeLayout> <LinearLayout android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_marginTop="@dimen/me_login_balance_layout_marginTop" android:layout_marginStart="@dimen/me_login_profile_layout_marginStart"> <TextView android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="@string/me_login_balance" android:textSize="@dimen/me_login_balance_size"/> <TextView android:id="@+id/me_login_tv_balance" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="00.00" android:textSize="@dimen/textSize_16"/> </LinearLayout> </LinearLayout> <ImageView android:id="@+id/me_login_iv_arrow_right" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_alignParentRight="true" android:layout_centerVertical="true" android:layout_marginEnd="@dimen/me_login_head_marginEnd" android:src="@mipmap/icon_user_arrow_more"/> </RelativeLayout> <LinearLayout android:id="@+id/me_nologin_layout" android:layout_width="match_parent" android:layout_height="@dimen/me_login_layout_height" android:orientation="vertical" android:gravity="center" android:background="@mipmap/my_login_bg"> <TextView android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="@string/me_nologin_not_login" android:textSize="@dimen/me_nologin_textSize" android:textColor="@color/grad"/> <Button android:id="@+id/me_nologin_btn_login" android:layout_width="80dp" android:layout_height="30dp" android:layout_marginTop="10dp" android:text="@string/me_nologin_login" android:textSize="@dimen/me_nologin_textSize" android:textColor="@color/grad" android:background="@drawable/login_btn_bg_selector"/> </LinearLayout> <LinearLayout android:layout_width="match_parent" android:layout_height="wrap_content" android:padding="5dp" android:background="@drawable/white_quai_bg" android:orientation="horizontal"> <TextView android:id="@+id/me_user_tv_cart" style="@style/me_userLayout_textView_style" android:drawableTop="@mipmap/user_icon_lashouquan" android:text="@string/me_user_cart"/> <View style="@style/me_vertical_view_style"/> <TextView android:id="@+id/me_user_tv_favorite" style="@style/me_userLayout_textView_style" android:drawableTop="@mipmap/user_icon_favorite" android:text="@string/me_user_favorite"/> <View style="@style/me_vertical_view_style"/> <TextView android:id="@+id/me_user_tv_history" style="@style/me_userLayout_textView_style" android:drawableTop="@mipmap/user_icon_history" android:text="@string/me_user_history"/> </LinearLayout> <LinearLayout android:id="@+id/me_user_order_layout" android:layout_width="match_parent" android:layout_height="wrap_content" android:orientation="vertical" android:background="@drawable/white_quai_bg"> <RelativeLayout android:id="@+id/me_item_unpaid_layout" style="@style/me_common_item_relativeLayout_style"> <ImageView android:id="@+id/me_item_unpaid_iv_icon" style="@style/me_common_item_icon_imageView_style" android:src="@mipmap/user_listicon_daifukuan"/> <TextView style="@style/me_common_item_title_textView_style" android:layout_toRightOf="@+id/me_item_unpaid_iv_icon" android:text="@string/me_item_unpaid_order"/> <ImageView android:id="@+id/me_item_unpaid_iv_arrow_right" style="@style/me_common_item_arrow_right_imageView_style"/> <TextView android:id="@+id/me_item_unpaid_tv_count" android:layout_toLeftOf="@+id/me_item_unpaid_iv_arrow_right" android:textColor="@color/white" android:background="@mipmap/num_red_bg" style="@style/me_common_item_count_textView_style" android:text="1"/> </RelativeLayout> <View style="@style/me_horizontal_view_style"/> <RelativeLayout android:id="@+id/me_item_paid_order_layout" style="@style/me_common_item_relativeLayout_style"> <ImageView android:id="@+id/me_item_paid_iv_icon" style="@style/me_common_item_icon_imageView_style" android:src="@mipmap/user_listicon_yifukuan"/> <TextView style="@style/me_common_item_title_textView_style" android:layout_toRightOf="@+id/me_item_paid_iv_icon" android:text="@string/me_item_paid_order"/> <ImageView android:id="@+id/me_item_paid_iv_arrow_right" style="@style/me_common_item_arrow_right_imageView_style"/> <TextView android:id="@+id/me_item_paid_tv_count" android:layout_toLeftOf="@+id/me_item_paid_iv_arrow_right" style="@style/me_common_item_count_textView_style" tools:text="1"/> <TextView android:id="@+id/me_item_paid_tv_uncomment_count" style="@style/me_common_item_count_textView_style" android:layout_toLeftOf="@+id/me_item_paid_iv_arrow_right" android:background="@drawable/movie_group_good_buy_d" android:paddingLeft="5.0dip" android:paddingRight="5.0dip" android:text="@string/me_item_unpaid_uncomment" android:textColor="@color/white" android:visibility="gone"/> </RelativeLayout> <View style="@style/me_horizontal_view_style"/> <RelativeLayout android:id="@+id/me_item_lottery_layout" style="@style/me_common_item_relativeLayout_style"> <ImageView android:id="@+id/me_item_lottery_iv_icon" style="@style/me_common_item_icon_imageView_style" android:src="@mipmap/user_listicon_choujiang"/> <TextView style="@style/me_common_item_title_textView_style" android:layout_toRightOf="@+id/me_item_lottery_iv_icon" android:text="@string/me_item_lottery_order"/> <ImageView android:id="@+id/me_item_lottery_iv_arrow_right" style="@style/me_common_item_arrow_right_imageView_style"/> <TextView android:id="@+id/me_item_lottery_tv_count" android:layout_toLeftOf="@+id/me_item_lottery_iv_arrow_right" style="@style/me_common_item_count_textView_style" tools:text="1"/> </RelativeLayout> <View style="@style/me_horizontal_view_style"/> <RelativeLayout android:id="@+id/me_item_treasure_layout" style="@style/me_common_item_relativeLayout_style"> <ImageView android:id="@+id/me_item_treasure_iv_icon" style="@style/me_common_item_icon_imageView_style" android:src="@mipmap/user_generdisplay_img"/> <TextView style="@style/me_common_item_title_textView_style" android:layout_toRightOf="@+id/me_item_treasure_iv_icon" android:text="@string/me_item_treasure_order"/> <ImageView android:id="@+id/me_item_treasure_iv_arrow_right" style="@style/me_common_item_arrow_right_imageView_style"/> <TextView android:id="@+id/me_item_treasure_tv_count" android:layout_toLeftOf="@+id/me_item_treasure_iv_arrow_right" style="@style/me_common_item_count_textView_style" tools:text="1"/> </RelativeLayout> </LinearLayout> <RelativeLayout android:id="@+id/me_item_bankcard_layout" style="@style/me_common_item_relativeLayout_style" android:layout_marginTop="@dimen/me_item_common_layout_marginTop" android:visibility="gone"> <ImageView android:id="@+id/me_item_bankcard_iv_icon" style="@style/me_common_item_icon_imageView_style" android:src="@mipmap/user_icon_yinhangka"/> <TextView style="@style/me_common_item_title_textView_style" android:layout_toRightOf="@+id/me_item_bankcard_iv_icon" android:text="@string/me_item_bankcard"/> <ImageView android:id="@+id/me_item_bankcard_iv_arrow_right" style="@style/me_common_item_arrow_right_imageView_style"/> <TextView android:id="@+id/me_item_bankcard_tv_complete" android:layout_toLeftOf="@+id/me_item_bankcard_iv_arrow_right" style="@style/me_common_item_count_textView_style" android:text="@string/me_item_bankcard_go_complete"/> </RelativeLayout> <RelativeLayout android:id="@+id/me_item_coupons_layout" style="@style/me_common_item_relativeLayout_style" android:layout_marginTop="@dimen/me_item_common_layout_marginTop" android:visibility="gone"> <ImageView android:id="@+id/me_item_coupons_iv_icon" style="@style/me_common_item_icon_imageView_style" android:src="@mipmap/user_listicon_diyongquan"/> <TextView style="@style/me_common_item_title_textView_style" android:layout_toRightOf="@+id/me_item_coupons_iv_icon" android:text="@string/me_item_coupons"/> <ImageView android:id="@+id/me_item_coupons_iv_arrow_right" style="@style/me_common_item_arrow_right_imageView_style"/> <TextView android:id="@+id/me_item_coupons_tv_count" android:layout_toLeftOf="@+id/me_item_coupons_iv_arrow_right" style="@style/me_common_item_count_textView_style" tools:text="1"/> </RelativeLayout> <RelativeLayout android:id="@+id/me_item_recommend_layout" style="@style/me_common_item_relativeLayout_style" android:layout_marginTop="@dimen/me_item_common_layout_marginTop"> <ImageView android:id="@+id/me_item_recommend_iv_icon" style="@style/me_common_item_icon_imageView_style" android:src="@mipmap/user_listicon_tuijian"/> <TextView style="@style/me_common_item_title_textView_style" android:layout_toRightOf="@+id/me_item_recommend_iv_icon" android:text="@string/me_item_recommend"/> <ImageView android:id="@+id/me_item_recommend_iv_arrow_right" style="@style/me_common_item_arrow_right_imageView_style"/> <TextView android:id="@+id/me_item_recommend_tv_new" style="@style/me_common_item_count_textView_style" android:layout_toLeftOf="@+id/me_item_recommend_iv_arrow_right" android:background="@drawable/orange_bg" android:text="new" android:textColor="@color/white" android:textSize="@dimen/textSize_12"/> </RelativeLayout> <RelativeLayout android:id="@+id/me_item_qr_layout" style="@style/me_common_item_relativeLayout_style" android:layout_marginTop="@dimen/me_item_common_layout_marginTop"> <ImageView android:id="@+id/me_item_qr_iv_icon" style="@style/me_common_item_icon_imageView_style" android:src="@mipmap/nav_icon_scan_sel"/> <TextView style="@style/me_common_item_title_textView_style" android:layout_toRightOf="@+id/me_item_qr_iv_icon" android:text="@string/me_item_qr"/> <ImageView android:id="@+id/me_item_qr_iv_arrow_right" style="@style/me_common_item_arrow_right_imageView_style"/> </RelativeLayout> </LinearLayout> </ScrollView> </LinearLayout>
MeFragment.java
public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) { View view = inflater.inflate(R.layout.fragment_me, null); initView(view); initUserLayout(); return view; } private void initUserLayout() { User user = User.getCurrentUser(User.class); if (user != null) { mLoginLayout.setVisibility(View.VISIBLE); mNologinLayout.setVisibility(View.GONE); mItemBankcardLayout.setVisibility(View.VISIBLE); mItemCouponsLayout.setVisibility(View.VISIBLE); mLoginTvUsername.setText(user.getUsername()); mLoginTvBalance.setText(user.getBalance() + ""); if (user.getHeadIcon() == null) { mLoginIvHead.setImageResource(R.mipmap.user_head); } else { mLoginIvHead.setImageURI(Uri.parse(user.getHeadIcon().getFileUrl())); } } else { mLoginLayout.setVisibility(View.GONE); mNologinLayout.setVisibility(View.VISIBLE); mItemBankcardLayout.setVisibility(View.GONE); mItemCouponsLayout.setVisibility(View.GONE); } }
@Override public void onClick(View v) { switch (v.getId()) { case R.id.me_login_profile_layout: Intent profileIntent = new Intent(getActivity(), UserProfileActivity.class); startActivityForResult(profileIntent, PROFILE_REQUEST_CODE); break; case R.id.me_nologin_btn_login: Intent intent = new Intent(getActivity(), LoginActivity.class); startActivityForResult(intent, LOGIN_REQUEST_CODE); break; case R.id.me_item_qr_layout: Intent qrIntent = new Intent(getActivity(), CaptureActivity.class); getActivity().startActivityForResult(qrIntent,SCAN_QR_REQUEST); break; } } @Override public void onActivityResult(int requestCode, int resultCode, Intent data) { if (requestCode == LOGIN_REQUEST_CODE && resultCode == LoginActivity.LOGIN_RESULT_CODE) { initUserLayout(); } else if (requestCode == PROFILE_REQUEST_CODE && resultCode == UserProfileActivity.PROFILE_RESULT_CODE) { initUserLayout(); } else if (requestCode == SCAN_QR_REQUEST) { } super.onActivityResult(requestCode, resultCode, data); }