通过fragmen跳转到个人信息界面
个人信息界面我们为了使界面更加美观,头像制作为圆形不留白
RoundImagView
package com.example.fuxing.widget; import android.content.Context; import android.graphics.Canvas; import android.graphics.Color; import android.graphics.Paint; import android.graphics.PorterDuff; import android.graphics.PorterDuffXfermode; import android.graphics.RectF; import android.util.AttributeSet; import androidx.appcompat.widget.AppCompatImageView; public class RoundImageView extends AppCompatImageView { public RoundImageView(Context context, AttributeSet attrs) { super(context, attrs); init(); } public RoundImageView(Context context) { super(context); init(); } private final RectF roundRect = new RectF(); private float rect_adius = 90; private final Paint maskPaint = new Paint(); private final Paint zonePaint = new Paint(); private void init() { maskPaint.setAntiAlias(true); maskPaint.setXfermode(new PorterDuffXfermode( PorterDuff.Mode.SRC_IN)); maskPaint.setFilterBitmap(true); zonePaint.setAntiAlias(true); zonePaint.setColor( Color.WHITE); zonePaint.setFilterBitmap(true); float density = getResources().getDisplayMetrics().density; rect_adius = rect_adius * density; } public void setRectAdius(float adius) { rect_adius = adius; invalidate(); } @Override protected void onLayout(boolean changed, int left, int top, int right, int bottom) { super.onLayout(changed, left, top, right, bottom); int w = getWidth(); int h = getHeight(); roundRect.set(0, 0, w, h); } @Override public void draw(Canvas canvas) { canvas.saveLayer(roundRect, zonePaint, Canvas.ALL_SAVE_FLAG); canvas.drawRoundRect(roundRect, rect_adius, rect_adius, zonePaint); // canvas.saveLayer(roundRect, maskPaint, Canvas.ALL_SAVE_FLAG); super.draw(canvas); canvas.restore(); } }
ItemGroup.java
package com.example.fuxing.widget; import android.content.Context; import android.content.Intent; import android.content.res.TypedArray; import android.util.AttributeSet; import android.view.LayoutInflater; import android.view.View; import android.widget.Button; import android.widget.FrameLayout; import android.widget.ImageView; import android.widget.LinearLayout; import android.widget.TextView; import androidx.annotation.AttrRes; import androidx.annotation.NonNull; import androidx.annotation.Nullable; import com.example.fuxing.Fragment_3; import com.example.fuxing.MainActivity; import com.example.fuxing.R; import com.example.fuxing.UserActivity; public class ItemGroup extends FrameLayout { private LinearLayout itemGroupLayout; //组合控件的布局 private TextView titleTv; //标题 private TextView contentEdt; //输入框 private ImageView jtRightIv; //向右的箭头 public TextView getContentEdt() { return contentEdt; } public ItemGroup(@NonNull Context context) { super(context); initView(context); } public ItemGroup(@NonNull Context context, @Nullable AttributeSet attrs) { super(context, attrs); initView(context); initAttrs(context, attrs); } public ItemGroup(@NonNull Context context, @Nullable AttributeSet attrs, @AttrRes int defStyleAttr) { super(context, attrs, defStyleAttr); initView(context); initAttrs(context,attrs); } //初始化View private void initView(Context context) { View view = LayoutInflater.from(context).inflate( R.layout.activity_item_group, null); itemGroupLayout = (LinearLayout) view.findViewById(R.id.item_group_layout); titleTv = (TextView) view.findViewById(R.id.title_tv); contentEdt = (TextView) view.findViewById(R.id.content_edt); jtRightIv = (ImageView) view.findViewById(R.id.jt_right_iv); addView(view); //把自定义的这个组合控件的布局加入到当前FramLayout } /** * 初始化相关属性,引入相关属性 * * @param context * @param attrs */ private void initAttrs(Context context, AttributeSet attrs) { //标题的默认字体颜色 int defaultTitleColor = context.getResources().getColor(R.color.gray3); //输入框的默认字体颜色 int defaultEdtColor = context.getResources().getColor(R.color.black); //输入框的默认的提示内容的字体颜色 int defaultHintColor = context.getResources().getColor(R.color.gray3); TypedArray typedArray = context.obtainStyledAttributes(attrs, R.styleable.ItemGroup); String title = typedArray.getString(R.styleable.ItemGroup_title); float paddingLeft = typedArray.getDimension(R.styleable.ItemGroup_paddingLeft, 15); float paddingRight = typedArray.getDimension(R.styleable.ItemGroup_paddingRight, 15); float paddingTop = typedArray.getDimension(R.styleable.ItemGroup_paddingTop, 5); float paddingBottom = typedArray.getDimension(R.styleable.ItemGroup_paddingTop, 5); float titleSize = typedArray.getDimension(R.styleable.ItemGroup_title_size, 15); int titleColor = typedArray.getColor(R.styleable.ItemGroup_title_color, defaultTitleColor); String content = typedArray.getString(R.styleable.ItemGroup_edt_content); float contentSize = typedArray.getDimension(R.styleable.ItemGroup_edt_text_size, 13); int contentColor = typedArray.getColor(R.styleable.ItemGroup_edt_text_color, defaultEdtColor); String hintContent = typedArray.getString(R.styleable.ItemGroup_edt_hint_content); int hintColor = typedArray.getColor(R.styleable.ItemGroup_edt_hint_text_color, defaultHintColor); //默认输入框可以编辑 boolean isEditable = typedArray.getBoolean(R.styleable.ItemGroup_isEditable, true); //向右的箭头图标是否可见,默认可见 boolean showJtIcon = typedArray.getBoolean(R.styleable.ItemGroup_jt_visible, true); typedArray.recycle(); //设置数据 //设置item的内边距 itemGroupLayout.setPadding((int) paddingLeft, (int) paddingTop, (int) paddingRight, (int) paddingBottom); titleTv.setText(title); titleTv.setTextSize(titleSize); titleTv.setTextColor(titleColor); contentEdt.setText(content); contentEdt.setTextSize(contentSize); contentEdt.setTextColor(contentColor); contentEdt.setHint(hintContent); contentEdt.setHintTextColor(hintColor); // contentEdt.setFocusable(isEditable); //设置输入框是否可以编辑 // contentEdt.setClickable(true); // contentEdt.setKeyListener(null); jtRightIv.setVisibility(showJtIcon ? View.VISIBLE : View.GONE); //设置向右的箭头图标是否可见 } }
在最上方的标题栏也制作了
TitleLayout.java文件
package com.example.fuxing.widget; import android.app.Activity; import android.content.Context; import android.content.Intent; import android.util.AttributeSet; import android.view.LayoutInflater; import android.view.View; import android.widget.ImageView; import android.widget.LinearLayout; import android.widget.TextView; import com.example.fuxing.LoginActivity; import com.example.fuxing.R; import com.example.fuxing.RegisterActivity; public class TitleLayout extends LinearLayout { private ImageView iv_backward; private TextView tv_title, tv_forward; public TitleLayout(Context context, AttributeSet attrs) { super(context, attrs); LinearLayout bar_title = (LinearLayout) LayoutInflater.from(context).inflate( R.layout.activity_title, this); iv_backward = (ImageView) bar_title.findViewById(R.id.iv_backward); tv_title = (TextView) bar_title.findViewById(R.id.tv_title); tv_forward = (TextView) bar_title.findViewById(R.id.tv_forward); //设置监听器 //如果点击back则结束活动 iv_backward.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { ((Activity)getContext()).finish(); } }); } }
这三个文件都放在widget包中