personalcenter

master
ongbo 5 years ago
parent 1eebc6509e
commit c7f1d9b13b

@ -1,10 +1,13 @@
package com.example.PersonalCenter;
import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.Button;
import android.widget.TextView;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
@ -15,12 +18,20 @@ import androidx.fragment.app.Fragment;
import androidx.fragment.app.FragmentStatePagerAdapter;
import androidx.viewpager.widget.ViewPager;
import com.example.PersonalCenter.Login_Register.LoginActivity;
import com.example.Util.User;
import com.example.cmknowledgegraph.MainActivity;
import com.example.cmknowledgegraph.R;
import com.github.florent37.materialviewpager.MaterialViewPager;
import com.github.florent37.materialviewpager.header.HeaderDesign;
import de.hdodenhof.circleimageview.CircleImageView;
public class MyPersonCenter extends Fragment {
private CircleImageView iv_avatar;
private TextView iv_avatar_username;
MainActivity mainActivity;
@Override
public void onAttach(Context context) {
@ -39,6 +50,18 @@ public class MyPersonCenter extends Fragment {
super.onActivityCreated(savedInstanceState);
//包装处理逻辑
//得到MaterViewPager实例
iv_avatar = mainActivity.findViewById(R.id.iv_avatar);
iv_avatar_username = mainActivity.findViewById(R.id.iv_avatar_username);
iv_avatar.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
if(!User.isLogin){
Intent intent=new Intent();
intent.setClass(getActivity(), LoginActivity.class);
startActivity(intent);
}
}
});
MaterialViewPager materialViewPager = (MaterialViewPager) getActivity().findViewById(R.id.materialViewPager);
//为MaterialViewPager添加监听
materialViewPager.setMaterialViewPagerListener(new MaterialViewPager.Listener() {
@ -120,4 +143,13 @@ public class MyPersonCenter extends Fragment {
.getViewPager().getAdapter().getCount());
materialViewPager.getPagerTitleStrip().setViewPager(materialViewPager.getViewPager());
}
@Override
public void onResume() {
super.onResume();
if(User.isLogin){
iv_avatar_username.setText("Hello"+User.getUser().getUsername());
}
}
}

Binary file not shown.

After

Width:  |  Height:  |  Size: 18 KiB

@ -18,7 +18,7 @@
app:viewpager_logo="@layout/header_logo"
app:viewpager_logoMarginTop="100dp"
app:viewpager_color="@color/colorPrimary"
app:viewpager_headerHeight="200dp"
app:viewpager_headerHeight="300dp"
app:viewpager_headerAlpha="1.0"
app:viewpager_hideLogoWithFade="false"
app:viewpager_hideToolbarAndTitle="true"
@ -29,17 +29,7 @@
app:viewpager_transparentToolbar="true"
app:viewpager_animatedHeaderImage="true"
app:viewpager_disableToolbar="false">
<RelativeLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginBottom="40dp"
>
<de.hdodenhof.circleimageview.CircleImageView
android:layout_width="40dp"
android:layout_height="30dp"
android:src="@drawable/home_back_1"
/>
</RelativeLayout>
</com.github.florent37.materialviewpager.MaterialViewPager>
</LinearLayout>

@ -1,12 +1,34 @@
<?xml version="1.0" encoding="utf-8"?>
<!--这是chat区配置上面logo区域这里默认是Health isEverything-->
<TextView xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/logo_white"
android:layout_width="wrap_content"
android:layout_height="@dimen/materialviewpager_logoHeight"
android:text="Health is Everything"
android:textSize="30sp"
android:textColor="@android:color/white"/>
<!--<TextView xmlns:android="http://schemas.android.com/apk/res/android"-->
<!-- android:id="@+id/logo_white"-->
<!-- android:layout_width="wrap_content"-->
<!-- android:layout_height="@dimen/materialviewpager_logoHeight"-->
<!-- android:text="Health is Everything"-->
<!-- android:textSize="30sp"-->
<!-- android:textColor="@android:color/white"/>-->
<RelativeLayout android:layout_width="wrap_content"
android:layout_height="wrap_content"
xmlns:android="http://schemas.android.com/apk/res/android">
<de.hdodenhof.circleimageview.CircleImageView
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/iv_avatar"
android:layout_width="45dp"
android:layout_height="45dp"
android:src="@drawable/th"
/>
<TextView
android:id="@+id/iv_avatar_username"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:layout_below="@id/iv_avatar"
android:text="未登录"
android:textSize="20dp"
android:textColor="#1f330f"/>
</RelativeLayout>

Loading…
Cancel
Save