parent
3c6844b51f
commit
f3d857fb68
@ -1,90 +0,0 @@
|
|||||||
//package com.example.HomeContent;
|
|
||||||
//
|
|
||||||
//import android.content.Context;
|
|
||||||
//import android.view.LayoutInflater;
|
|
||||||
//import android.view.View;
|
|
||||||
//import android.view.ViewGroup;
|
|
||||||
//import android.widget.FrameLayout;
|
|
||||||
//import android.widget.ImageButton;
|
|
||||||
//import android.widget.ImageView;
|
|
||||||
//import android.widget.TextSwitcher;
|
|
||||||
//
|
|
||||||
//import androidx.annotation.NonNull;
|
|
||||||
//import androidx.recyclerview.widget.RecyclerView;
|
|
||||||
//
|
|
||||||
//import com.example.PersonalCenter.FeedAdapter;
|
|
||||||
//import com.example.cmknowledgegraph.R;
|
|
||||||
//
|
|
||||||
//public class HomeAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder> {
|
|
||||||
// private Context context;
|
|
||||||
// private int itemsCount = 0;
|
|
||||||
//
|
|
||||||
// public HomeAdapter(Context context){this.context = context;}
|
|
||||||
//
|
|
||||||
//
|
|
||||||
// @NonNull
|
|
||||||
// @Override
|
|
||||||
// public RecyclerView.ViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
|
|
||||||
// final View view = LayoutInflater.from(context).inflate(R.layout.item_feed, parent, false);
|
|
||||||
//
|
|
||||||
// return new HomeAdapter.CellFeedViewHolder(view);
|
|
||||||
// }
|
|
||||||
//
|
|
||||||
// @Override
|
|
||||||
// public void onBindViewHolder(@NonNull RecyclerView.ViewHolder holder, int position) {
|
|
||||||
// final FeedAdapter.CellFeedViewHolder holder = (FeedAdapter.CellFeedViewHolder) viewHolder;
|
|
||||||
// bindDefaultFeedItem(position, holder);
|
|
||||||
// }
|
|
||||||
// private void bindDefaultFeedItem(int position, FeedAdapter.CellFeedViewHolder holder) {
|
|
||||||
// if (position % 2 == 0) {
|
|
||||||
// holder.ivFeedCenter.setImageResource(R.drawable.img_feed_center_1);
|
|
||||||
// holder.ivFeedBottom.setImageResource(R.drawable.img_feed_bottom_1);
|
|
||||||
// } else {
|
|
||||||
// holder.ivFeedCenter.setImageResource(R.drawable.img_feed_center_2);
|
|
||||||
// holder.ivFeedBottom.setImageResource(R.drawable.img_feed_bottom_2);
|
|
||||||
// }
|
|
||||||
//
|
|
||||||
// holder.btnComments.setTag(position);
|
|
||||||
// holder.btnMore.setTag(position);
|
|
||||||
// holder.ivFeedCenter.setTag(holder);
|
|
||||||
// holder.btnLike.setTag(holder);
|
|
||||||
//
|
|
||||||
// }
|
|
||||||
// public void updateItems() {
|
|
||||||
// itemsCount = 10;
|
|
||||||
// notifyDataSetChanged();
|
|
||||||
// }
|
|
||||||
// @Override
|
|
||||||
// public int getItemCount() {
|
|
||||||
// return itemsCount;
|
|
||||||
// }
|
|
||||||
//
|
|
||||||
// @Override
|
|
||||||
// public int getItemViewType(int position) {
|
|
||||||
// return 1;
|
|
||||||
// }
|
|
||||||
//// 在这里构建一个cell的内容
|
|
||||||
// private static class CellFeedViewHolder extends RecyclerView.ViewHolder {
|
|
||||||
// ImageView ivFeedCenter;
|
|
||||||
// ImageView ivFeedBottom;
|
|
||||||
// ImageButton btnComments;
|
|
||||||
// ImageButton btnLike;
|
|
||||||
// ImageButton btnMore;
|
|
||||||
// TextSwitcher tsLikesCounter;
|
|
||||||
// ImageView ivUserProfile;
|
|
||||||
// FrameLayout vImageRoot;
|
|
||||||
//
|
|
||||||
// CellFeedViewHolder(View view) {
|
|
||||||
// super(view);
|
|
||||||
//
|
|
||||||
// ivFeedCenter = (ImageView) view.findViewById(R.id.ivFeedCenter);
|
|
||||||
// ivFeedBottom = (ImageView) view.findViewById(R.id.ivFeedBottom);
|
|
||||||
// btnComments = (ImageButton) view.findViewById(R.id.btnComments);
|
|
||||||
// btnLike = (ImageButton) view.findViewById(R.id.btnLike);
|
|
||||||
// btnMore = (ImageButton) view.findViewById(R.id.btnMore);
|
|
||||||
// tsLikesCounter = (TextSwitcher) view.findViewById(R.id.tsLikesCounter);
|
|
||||||
// ivUserProfile = (ImageView) view.findViewById(R.id.ivUserProfile);
|
|
||||||
// vImageRoot = (FrameLayout) view.findViewById(R.id.vImageRoot);
|
|
||||||
// }
|
|
||||||
// }
|
|
||||||
//}
|
|
@ -0,0 +1,54 @@
|
|||||||
|
package com.example.HomeContent;
|
||||||
|
|
||||||
|
|
||||||
|
/*
|
||||||
|
* 保存药文推送信息的一些信息bean
|
||||||
|
*
|
||||||
|
* */
|
||||||
|
|
||||||
|
|
||||||
|
public class SlideBean {
|
||||||
|
private int mItemBg;
|
||||||
|
private String mTitle;
|
||||||
|
private int mUserIcon;
|
||||||
|
private String mUserSay;
|
||||||
|
|
||||||
|
public SlideBean(int mItemBg, String mTitle, int mUserIcon, String mUserSay) {
|
||||||
|
this.mItemBg = mItemBg;
|
||||||
|
this.mTitle = mTitle;
|
||||||
|
this.mUserIcon = mUserIcon;
|
||||||
|
this.mUserSay = mUserSay;
|
||||||
|
}
|
||||||
|
|
||||||
|
public int getItemBg() {
|
||||||
|
return mItemBg;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setItemBg(int mItemBg) {
|
||||||
|
this.mItemBg = mItemBg;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getTitle() {
|
||||||
|
return mTitle;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setTitle(String mTitle) {
|
||||||
|
this.mTitle = mTitle;
|
||||||
|
}
|
||||||
|
|
||||||
|
public int getUserIcon() {
|
||||||
|
return mUserIcon;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setUserIcon(int mUserIcon) {
|
||||||
|
this.mUserIcon = mUserIcon;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getUserSay() {
|
||||||
|
return mUserSay;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setUserSay(String mUserSay) {
|
||||||
|
this.mUserSay = mUserSay;
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,185 @@
|
|||||||
|
package com.example.HomeContent;
|
||||||
|
|
||||||
|
import android.os.Bundle;
|
||||||
|
import android.util.Log;
|
||||||
|
import android.view.LayoutInflater;
|
||||||
|
import android.view.View;
|
||||||
|
import android.view.ViewGroup;
|
||||||
|
import android.widget.ImageView;
|
||||||
|
import android.widget.TextView;
|
||||||
|
|
||||||
|
import androidx.annotation.NonNull;
|
||||||
|
import androidx.annotation.Nullable;
|
||||||
|
import androidx.appcompat.app.AppCompatActivity;
|
||||||
|
import androidx.fragment.app.Fragment;
|
||||||
|
import androidx.recyclerview.widget.ItemTouchHelper;
|
||||||
|
import androidx.recyclerview.widget.RecyclerView;
|
||||||
|
|
||||||
|
import com.dingmouren.layoutmanagergroup.slide.ItemConfig;
|
||||||
|
import com.dingmouren.layoutmanagergroup.slide.ItemTouchHelperCallback;
|
||||||
|
import com.dingmouren.layoutmanagergroup.slide.OnSlideListener;
|
||||||
|
import com.dingmouren.layoutmanagergroup.slide.SlideLayoutManager;
|
||||||
|
import com.example.cmknowledgegraph.R;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
public class SlideFragment extends Fragment {
|
||||||
|
private static final String TAG = "SlideFragment";
|
||||||
|
private RecyclerView mRecyclerView;
|
||||||
|
private SmileView mSmileView;
|
||||||
|
private SlideLayoutManager mSlideLayoutManager;
|
||||||
|
private ItemTouchHelper mItemTouchHelper;
|
||||||
|
private ItemTouchHelperCallback mItemTouchHelperCallback;
|
||||||
|
private MyAdapter mAdapter;
|
||||||
|
private List<SlideBean> mList = new ArrayList<>();
|
||||||
|
private int mLikeCount = 50;
|
||||||
|
private int mDislikeCount = 50;
|
||||||
|
|
||||||
|
AppCompatActivity appCompatActivity;//保存最初的主Activity
|
||||||
|
public AppCompatActivity getAppCompatActivity(){
|
||||||
|
return appCompatActivity;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setAppCompatActivity(AppCompatActivity appCompatActivity) {
|
||||||
|
this.appCompatActivity = appCompatActivity;
|
||||||
|
}
|
||||||
|
|
||||||
|
private static final SlideFragment ourInstance = new SlideFragment();
|
||||||
|
|
||||||
|
public static SlideFragment getInstance() {
|
||||||
|
return ourInstance;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
@Nullable
|
||||||
|
@Override
|
||||||
|
public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
|
||||||
|
View rootView = inflater.inflate(R.layout.fragment_slide, container, false);
|
||||||
|
initView(rootView);
|
||||||
|
initListener();//初始化监听器
|
||||||
|
return rootView;
|
||||||
|
}
|
||||||
|
|
||||||
|
private void initView(View rootView) {
|
||||||
|
mRecyclerView = rootView.findViewById(R.id.recycler_view);//加载RecyclerView
|
||||||
|
mSmileView = rootView.findViewById(R.id.smile_view);//加载表情图片
|
||||||
|
|
||||||
|
mSmileView.setLike(mLikeCount);//设置表情喜欢
|
||||||
|
mSmileView.setDisLike(mDislikeCount);//设置表情不喜欢
|
||||||
|
|
||||||
|
mAdapter = new MyAdapter();//增添适配器
|
||||||
|
mRecyclerView.setAdapter(mAdapter);//设置适配器
|
||||||
|
addData();//添加数据,向集合中添加数据,也就是说,要从服务器抽取推文数据加载过来
|
||||||
|
|
||||||
|
mItemTouchHelperCallback = new ItemTouchHelperCallback(mRecyclerView.getAdapter(), mList);
|
||||||
|
mItemTouchHelper = new ItemTouchHelper(mItemTouchHelperCallback);
|
||||||
|
mSlideLayoutManager = new SlideLayoutManager(mRecyclerView, mItemTouchHelper);
|
||||||
|
mItemTouchHelper.attachToRecyclerView(mRecyclerView);
|
||||||
|
mRecyclerView.setLayoutManager(mSlideLayoutManager);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
private void initListener() {
|
||||||
|
mItemTouchHelperCallback.setOnSlideListener(new OnSlideListener() {
|
||||||
|
@Override
|
||||||
|
public void onSliding(RecyclerView.ViewHolder viewHolder, float ratio, int direction) {
|
||||||
|
if (direction == ItemConfig.SLIDING_LEFT) {
|
||||||
|
} else if (direction == ItemConfig.SLIDING_RIGHT) {
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onSlided(RecyclerView.ViewHolder viewHolder, Object o, int direction) {
|
||||||
|
if (direction == ItemConfig.SLIDED_LEFT) {
|
||||||
|
mDislikeCount--;
|
||||||
|
mSmileView.setDisLike(mDislikeCount);
|
||||||
|
mSmileView.disLikeAnimation();
|
||||||
|
} else if (direction == ItemConfig.SLIDED_RIGHT) {
|
||||||
|
mLikeCount++;
|
||||||
|
mSmileView.setLike(mLikeCount);
|
||||||
|
mSmileView.likeAnimation();
|
||||||
|
}
|
||||||
|
int position = viewHolder.getAdapterPosition();
|
||||||
|
Log.e(TAG, "onSlided--position:" + position);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onClear() {
|
||||||
|
addData();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 向集合中添加数据
|
||||||
|
*/
|
||||||
|
private void addData(){
|
||||||
|
int[] icons = {R.mipmap.header_icon_1, R.mipmap.header_icon_2, R.mipmap.header_icon_3,
|
||||||
|
R.mipmap.header_icon_4, R.mipmap.header_icon_1, R.mipmap.header_icon_2};
|
||||||
|
String[] titles = {"Acknowledging", "Belief", "Confidence", "Dreaming", "Happiness", "Confidence"};
|
||||||
|
String[] says = {
|
||||||
|
"Do one thing at a time, and do well.",
|
||||||
|
"Keep on going never give up.",
|
||||||
|
"Whatever is worth doing is worth doing well.",
|
||||||
|
"I can because i think i can.",
|
||||||
|
"Jack of all trades and master of none.",
|
||||||
|
"Keep on going never give up.",
|
||||||
|
"Whatever is worth doing is worth doing well.",
|
||||||
|
};
|
||||||
|
int[] bgs = {
|
||||||
|
R.mipmap.img_slide_1,
|
||||||
|
R.mipmap.img_slide_2,
|
||||||
|
R.mipmap.img_slide_3,
|
||||||
|
R.mipmap.img_slide_4,
|
||||||
|
R.mipmap.img_slide_5,
|
||||||
|
R.mipmap.img_slide_6
|
||||||
|
};
|
||||||
|
|
||||||
|
for (int i = 0; i < 6; i++) {
|
||||||
|
mList.add(new SlideBean(bgs[i],titles[i],icons[i],says[i]));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 适配器
|
||||||
|
*/
|
||||||
|
class MyAdapter extends RecyclerView.Adapter<MyAdapter.ViewHolder> {
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
|
||||||
|
View view = LayoutInflater.from(appCompatActivity).inflate(R.layout.item_slide, parent, false);
|
||||||
|
return new ViewHolder(view);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onBindViewHolder(ViewHolder holder, int position) {
|
||||||
|
SlideBean bean = mList.get(position);
|
||||||
|
holder.imgBg.setImageResource(bean.getItemBg());
|
||||||
|
holder.tvTitle.setText(bean.getTitle());
|
||||||
|
holder.userIcon.setImageResource(bean.getUserIcon());
|
||||||
|
holder.userSay.setText(bean.getUserSay());
|
||||||
|
}
|
||||||
|
@Override
|
||||||
|
public int getItemCount() {
|
||||||
|
return mList.size();
|
||||||
|
}
|
||||||
|
|
||||||
|
public class ViewHolder extends RecyclerView.ViewHolder {
|
||||||
|
ImageView imgBg;
|
||||||
|
ImageView userIcon;
|
||||||
|
TextView tvTitle;
|
||||||
|
TextView userSay;
|
||||||
|
|
||||||
|
public ViewHolder(View itemView) {
|
||||||
|
super(itemView);
|
||||||
|
imgBg = itemView.findViewById(R.id.img_bg);
|
||||||
|
userIcon = itemView.findViewById(R.id.img_user);
|
||||||
|
tvTitle = itemView.findViewById(R.id.tv_title);
|
||||||
|
userSay = itemView.findViewById(R.id.tv_user_say);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,428 @@
|
|||||||
|
package com.example.HomeContent;
|
||||||
|
|
||||||
|
import android.animation.Animator;
|
||||||
|
import android.animation.AnimatorListenerAdapter;
|
||||||
|
import android.animation.ObjectAnimator;
|
||||||
|
import android.animation.ValueAnimator;
|
||||||
|
import android.content.Context;
|
||||||
|
import android.graphics.Color;
|
||||||
|
import android.graphics.drawable.AnimationDrawable;
|
||||||
|
import android.graphics.drawable.ColorDrawable;
|
||||||
|
import android.text.TextPaint;
|
||||||
|
import android.util.AttributeSet;
|
||||||
|
import android.view.Gravity;
|
||||||
|
import android.view.View;
|
||||||
|
import android.view.ViewGroup;
|
||||||
|
import android.widget.ImageView;
|
||||||
|
import android.widget.LinearLayout;
|
||||||
|
import android.widget.TextView;
|
||||||
|
|
||||||
|
import com.example.cmknowledgegraph.R;
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Created by DELL on 2017/7/25.
|
||||||
|
*/
|
||||||
|
public class SmileView extends LinearLayout implements Animator.AnimatorListener {
|
||||||
|
|
||||||
|
|
||||||
|
//分割线间距
|
||||||
|
private int dividerMargin = 20;
|
||||||
|
private float count;
|
||||||
|
private int defalutBottom = 70;
|
||||||
|
private String defaultLike = "喜欢";
|
||||||
|
private String defalutDis = "无感";
|
||||||
|
private int defalutTextColor = Color.WHITE;
|
||||||
|
private String defaluteShadow = "#7F484848";
|
||||||
|
private int defalutGravity = Gravity.CENTER_HORIZONTAL;
|
||||||
|
private int defalutSize = dip2px(getContext(), 25);
|
||||||
|
|
||||||
|
private int like = 20;
|
||||||
|
private int disLike = 20; //点赞数,差评数
|
||||||
|
private float fLike, fDis;
|
||||||
|
private ImageView imageLike;
|
||||||
|
private ImageView imageDis;
|
||||||
|
|
||||||
|
private TextView likeNum, disNum, likeText, disText;
|
||||||
|
private LinearLayout likeBack, disBack, likeAll, disAll;
|
||||||
|
private AnimationDrawable animLike, animDis; //笑脸帧动画
|
||||||
|
private ValueAnimator animatorBack; //背景拉伸动画
|
||||||
|
|
||||||
|
private int type = 0; //选择执行帧动画的笑脸 //0 笑脸 1 哭脸
|
||||||
|
private boolean isClose = false; //判断收起动画
|
||||||
|
|
||||||
|
public SmileView setDefalutBottom(int defalutBottom) {
|
||||||
|
this.defalutBottom = defalutBottom;
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void notifyChange() {
|
||||||
|
init();
|
||||||
|
bindListener();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public void setDefalutGravity(int defalutGravity) {
|
||||||
|
this.defalutGravity = defalutGravity;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setDefalutDis(String defalutDis) {
|
||||||
|
this.defalutDis = defalutDis;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setDefaultLike(String defaultLike) {
|
||||||
|
this.defaultLike = defaultLike;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
public SmileView setDividerMargin(int dividerMargin) {
|
||||||
|
this.dividerMargin = dividerMargin;
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public void setDefalutSize(int defalutSize) {
|
||||||
|
this.defalutSize = defalutSize;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setNum(int like, int dislike) {
|
||||||
|
//设置百分比
|
||||||
|
count = like + dislike;
|
||||||
|
fLike = like / count;
|
||||||
|
fDis = dislike / count;
|
||||||
|
this.like = (int) (fLike * 100);
|
||||||
|
this.disLike = 100 - this.like;
|
||||||
|
setLike(this.like);
|
||||||
|
setDisLike(this.disLike);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setLike(int like) {
|
||||||
|
likeNum.setText(like + "");
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setDisLike(int disLike) {
|
||||||
|
disNum.setText(disLike + "");
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public SmileView(Context context) {
|
||||||
|
this(context, null);
|
||||||
|
}
|
||||||
|
|
||||||
|
public SmileView(Context context, AttributeSet attrs) {
|
||||||
|
this(context, attrs, 0);
|
||||||
|
}
|
||||||
|
|
||||||
|
public SmileView(Context context, AttributeSet attrs, int defStyleAttr) {
|
||||||
|
super(context, attrs, defStyleAttr);
|
||||||
|
init();
|
||||||
|
bindListener();
|
||||||
|
}
|
||||||
|
|
||||||
|
private void init() {
|
||||||
|
this.removeAllViews();
|
||||||
|
//初始化总布局
|
||||||
|
setOrientation(HORIZONTAL);
|
||||||
|
setGravity(defalutGravity | Gravity.BOTTOM);
|
||||||
|
setBackgroundColor(Color.TRANSPARENT); //开始透明
|
||||||
|
|
||||||
|
|
||||||
|
//设置百分比
|
||||||
|
float count = like + disLike;
|
||||||
|
fLike = like / count;
|
||||||
|
fDis = disLike / count;
|
||||||
|
like = (int) (fLike * 100);
|
||||||
|
disLike = (int) (fDis * 100);
|
||||||
|
|
||||||
|
//初始化图片
|
||||||
|
imageLike = new ImageView(getContext());
|
||||||
|
//添加动画资源 获得帧动画
|
||||||
|
imageLike.setBackgroundResource(R.drawable.animation_like);
|
||||||
|
animLike = (AnimationDrawable) imageLike.getBackground();
|
||||||
|
//初始化文字
|
||||||
|
likeNum = new TextView(getContext());
|
||||||
|
likeNum.setText(like + "");
|
||||||
|
likeNum.setTextColor(defalutTextColor);
|
||||||
|
TextPaint likeNumPaint = likeNum.getPaint();
|
||||||
|
likeNumPaint.setFakeBoldText(true);
|
||||||
|
likeNum.setTextSize(20f);
|
||||||
|
likeText = new TextView(getContext());
|
||||||
|
likeText.setText(defaultLike);
|
||||||
|
likeText.setTextColor(defalutTextColor);
|
||||||
|
|
||||||
|
imageDis = new ImageView(getContext());
|
||||||
|
imageDis.setBackgroundResource(R.drawable.animation_dislike);
|
||||||
|
animDis = (AnimationDrawable) imageDis.getBackground();
|
||||||
|
disNum = new TextView(getContext());
|
||||||
|
disNum.setText(disLike + "");
|
||||||
|
disNum.setTextColor(defalutTextColor);
|
||||||
|
TextPaint disNumPaint = disNum.getPaint();
|
||||||
|
disNumPaint.setFakeBoldText(true);
|
||||||
|
disNum.setTextSize(20f);
|
||||||
|
disText = new TextView(getContext());
|
||||||
|
disText.setText(defalutDis);
|
||||||
|
disText.setTextColor(defalutTextColor);
|
||||||
|
|
||||||
|
|
||||||
|
//初始化布局
|
||||||
|
likeBack = new LinearLayout(getContext());
|
||||||
|
disBack = new LinearLayout(getContext());
|
||||||
|
LayoutParams params2 = new LayoutParams(defalutSize, defalutSize);
|
||||||
|
likeBack.addView(imageLike, params2);
|
||||||
|
disBack.addView(imageDis, params2);
|
||||||
|
disBack.setBackgroundResource(R.drawable.white_background);
|
||||||
|
likeBack.setBackgroundResource(R.drawable.white_background);
|
||||||
|
|
||||||
|
//单列总布局
|
||||||
|
likeAll = new LinearLayout(getContext());
|
||||||
|
disAll = new LinearLayout(getContext());
|
||||||
|
likeAll.setOrientation(VERTICAL);
|
||||||
|
disAll.setOrientation(VERTICAL);
|
||||||
|
likeAll.setGravity(Gravity.CENTER_HORIZONTAL);
|
||||||
|
disAll.setGravity(Gravity.CENTER_HORIZONTAL);
|
||||||
|
likeAll.setBackgroundColor(Color.TRANSPARENT);
|
||||||
|
disAll.setBackgroundColor(Color.TRANSPARENT);
|
||||||
|
|
||||||
|
//添加文字图片放进一列
|
||||||
|
LayoutParams params = new LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT);
|
||||||
|
params.setMargins(0, 10, 0, 0);
|
||||||
|
params.gravity = Gravity.CENTER;
|
||||||
|
disAll.setGravity(Gravity.CENTER_HORIZONTAL);
|
||||||
|
likeAll.setGravity(Gravity.RIGHT);
|
||||||
|
disAll.addView(disNum, params);
|
||||||
|
disAll.addView(disText, params);
|
||||||
|
disAll.addView(disBack, params);
|
||||||
|
|
||||||
|
likeAll.addView(likeNum, params);
|
||||||
|
likeAll.addView(likeText, params);
|
||||||
|
likeAll.addView(likeBack, params);
|
||||||
|
|
||||||
|
//中间分隔线
|
||||||
|
ImageView imageView = new ImageView(getContext());
|
||||||
|
imageView.setBackground(new ColorDrawable(Color.GRAY));
|
||||||
|
LayoutParams params4 = new LayoutParams(3, 80);
|
||||||
|
params4.setMargins(dividerMargin, 10, dividerMargin, defalutBottom + 20);
|
||||||
|
params4.gravity = Gravity.BOTTOM;
|
||||||
|
|
||||||
|
|
||||||
|
LayoutParams params3 = new LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT);
|
||||||
|
params3.setMargins(30, 20, 30, defalutBottom);
|
||||||
|
params3.gravity = Gravity.BOTTOM;
|
||||||
|
addView(disAll, params3);
|
||||||
|
addView(imageView, params4);
|
||||||
|
addView(likeAll, params3);
|
||||||
|
|
||||||
|
//隐藏文字
|
||||||
|
setVisibities(GONE);
|
||||||
|
}
|
||||||
|
|
||||||
|
//
|
||||||
|
public void setVisibities(int v) {
|
||||||
|
likeNum.setVisibility(v);
|
||||||
|
disNum.setVisibility(v);
|
||||||
|
likeText.setVisibility(v);
|
||||||
|
disText.setVisibility(v);
|
||||||
|
}
|
||||||
|
|
||||||
|
//绑定监听
|
||||||
|
private void bindListener() {
|
||||||
|
imageDis.setOnClickListener(new OnClickListener() {
|
||||||
|
@Override
|
||||||
|
public void onClick(View v) {
|
||||||
|
/* type = 1; //设置动画对象
|
||||||
|
animBack(); //拉伸背景
|
||||||
|
setVisibities(VISIBLE); //隐藏文字
|
||||||
|
//切换背景色
|
||||||
|
setBackgroundColor(Color.TRANSPARENT);
|
||||||
|
likeBack.setBackgroundResource(R.drawable.white_background);
|
||||||
|
disBack.setBackgroundResource(R.drawable.yellow_background);
|
||||||
|
//重置帧动画
|
||||||
|
imageLike.setBackground(null);
|
||||||
|
imageLike.setBackgroundResource(R.drawable.animation_like);
|
||||||
|
animLike = (AnimationDrawable) imageLike.getBackground();*/
|
||||||
|
disLikeAnimation();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
imageLike.setOnClickListener(new OnClickListener() {
|
||||||
|
@Override
|
||||||
|
public void onClick(View v) {
|
||||||
|
/* type = 0;
|
||||||
|
animBack();
|
||||||
|
setVisibities(VISIBLE);
|
||||||
|
setBackgroundColor(Color.TRANSPARENT);
|
||||||
|
disBack.setBackgroundResource(R.drawable.white_background);
|
||||||
|
likeBack.setBackgroundResource(R.drawable.yellow_background);
|
||||||
|
imageDis.setBackground(null);
|
||||||
|
imageDis.setBackgroundResource(R.drawable.animation_dislike);
|
||||||
|
animDis = (AnimationDrawable) imageDis.getBackground();*/
|
||||||
|
likeAnimation();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
public void disLikeAnimation(){
|
||||||
|
type = 1; //设置动画对象
|
||||||
|
animBack(); //拉伸背景
|
||||||
|
setVisibities(VISIBLE); //隐藏文字
|
||||||
|
//切换背景色
|
||||||
|
setBackgroundColor(Color.parseColor(defaluteShadow));
|
||||||
|
likeBack.setBackgroundResource(R.drawable.white_background);
|
||||||
|
disBack.setBackgroundResource(R.drawable.yellow_background);
|
||||||
|
//重置帧动画
|
||||||
|
imageLike.setBackground(null);
|
||||||
|
imageLike.setBackgroundResource(R.drawable.animation_like);
|
||||||
|
animLike = (AnimationDrawable) imageLike.getBackground();
|
||||||
|
}
|
||||||
|
|
||||||
|
public void likeAnimation(){
|
||||||
|
type = 0;
|
||||||
|
animBack();
|
||||||
|
setVisibities(VISIBLE);
|
||||||
|
setBackgroundColor(Color.parseColor(defaluteShadow));
|
||||||
|
disBack.setBackgroundResource(R.drawable.white_background);
|
||||||
|
likeBack.setBackgroundResource(R.drawable.yellow_background);
|
||||||
|
imageDis.setBackground(null);
|
||||||
|
imageDis.setBackgroundResource(R.drawable.animation_dislike);
|
||||||
|
animDis = (AnimationDrawable) imageDis.getBackground();
|
||||||
|
}
|
||||||
|
|
||||||
|
//背景伸展动画
|
||||||
|
public void animBack() {
|
||||||
|
//动画执行中不能点击
|
||||||
|
imageDis.setClickable(false);
|
||||||
|
imageLike.setClickable(false);
|
||||||
|
|
||||||
|
final int max = Math.max(like * 4, disLike * 4);
|
||||||
|
animatorBack = ValueAnimator.ofInt(5, max);
|
||||||
|
animatorBack.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {
|
||||||
|
@Override
|
||||||
|
public void onAnimationUpdate(ValueAnimator animation) {
|
||||||
|
int magrin = (int) animation.getAnimatedValue();
|
||||||
|
LayoutParams paramsLike
|
||||||
|
= (LayoutParams) imageLike.getLayoutParams();
|
||||||
|
paramsLike.bottomMargin = magrin;
|
||||||
|
|
||||||
|
if (magrin <= like * 4) {
|
||||||
|
imageLike.setLayoutParams(paramsLike);
|
||||||
|
}
|
||||||
|
if (magrin <= disLike * 4) {
|
||||||
|
imageDis.setLayoutParams(paramsLike);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
isClose = false;
|
||||||
|
animatorBack.addListener(this);
|
||||||
|
animatorBack.setDuration(500);
|
||||||
|
animatorBack.start();
|
||||||
|
}
|
||||||
|
|
||||||
|
//背景收回动画
|
||||||
|
public void setBackUp() {
|
||||||
|
final int max = Math.max(like * 4, disLike * 4);
|
||||||
|
animatorBack = ValueAnimator.ofInt(max, 5);
|
||||||
|
animatorBack.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {
|
||||||
|
@Override
|
||||||
|
public void onAnimationUpdate(ValueAnimator animation) {
|
||||||
|
int magrin = (int) animation.getAnimatedValue();
|
||||||
|
LayoutParams paramsLike
|
||||||
|
= (LayoutParams) imageLike.getLayoutParams();
|
||||||
|
paramsLike.bottomMargin = magrin;
|
||||||
|
|
||||||
|
if (magrin <= like * 4) {
|
||||||
|
imageLike.setLayoutParams(paramsLike);
|
||||||
|
}
|
||||||
|
if (magrin <= disLike * 4) {
|
||||||
|
imageDis.setLayoutParams(paramsLike);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
animatorBack.addListener(this);
|
||||||
|
animatorBack.setDuration(500);
|
||||||
|
animatorBack.start();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onAnimationEnd(Animator animation) {
|
||||||
|
//重置帧动画
|
||||||
|
animDis.stop();
|
||||||
|
animLike.stop();
|
||||||
|
|
||||||
|
//关闭时不执行帧动画
|
||||||
|
if (isClose) {
|
||||||
|
//收回后可点击
|
||||||
|
imageDis.setClickable(true);
|
||||||
|
imageLike.setClickable(true);
|
||||||
|
//隐藏文字
|
||||||
|
setVisibities(GONE);
|
||||||
|
//恢复透明
|
||||||
|
setBackgroundColor(Color.TRANSPARENT);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
isClose = true;
|
||||||
|
|
||||||
|
if (type == 0) {
|
||||||
|
animLike.start();
|
||||||
|
objectY(imageLike);
|
||||||
|
} else {
|
||||||
|
animDis.start();
|
||||||
|
objectX(imageDis);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public void objectY(View view) {
|
||||||
|
ObjectAnimator animator = ObjectAnimator.ofFloat(view, "translationY", -10.0f, 0.0f, 10.0f, 0.0f, -10.0f, 0.0f, 10.0f, 0);
|
||||||
|
animator.setRepeatMode(ObjectAnimator.RESTART);
|
||||||
|
//animator.setRepeatCount(1);
|
||||||
|
animator.setDuration(1500);
|
||||||
|
animator.start();
|
||||||
|
animator.addListener(new AnimatorListenerAdapter() {
|
||||||
|
@Override
|
||||||
|
public void onAnimationEnd(Animator animation) {
|
||||||
|
setBackUp(); //执行回弹动画
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
public void objectX(View view) {
|
||||||
|
|
||||||
|
ObjectAnimator animator = ObjectAnimator.ofFloat(view, "translationX", -10.0f, 0.0f, 10.0f, 0.0f, -10.0f, 0.0f, 10.0f, 0);
|
||||||
|
animator.setRepeatMode(ObjectAnimator.RESTART);
|
||||||
|
// animator.setRepeatCount(1);
|
||||||
|
animator.setDuration(1500);
|
||||||
|
animator.start();
|
||||||
|
|
||||||
|
animator.addListener(new AnimatorListenerAdapter() {
|
||||||
|
@Override
|
||||||
|
public void onAnimationEnd(Animator animation) {
|
||||||
|
setBackUp(); //执行回弹动画
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onAnimationStart(Animator animation) {
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onAnimationCancel(Animator animation) {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onAnimationRepeat(Animator animation) {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
//dp转px
|
||||||
|
public static int dip2px(Context context, float dipValue) {
|
||||||
|
final float scale = context.getResources().getDisplayMetrics().density;
|
||||||
|
return (int) (dipValue * scale + 0.5f);
|
||||||
|
}
|
||||||
|
|
||||||
|
//px转dp
|
||||||
|
public static int px2dip(Context context, float pxValue) {
|
||||||
|
final float scale = context.getResources().getDisplayMetrics().density;
|
||||||
|
return (int) (pxValue / scale + 0.5f);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
@ -0,0 +1,18 @@
|
|||||||
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
|
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="match_parent"
|
||||||
|
android:background="@android:color/black"
|
||||||
|
xmlns:blurkit="http://schemas.android.com/apk/res-auto">
|
||||||
|
|
||||||
|
<androidx.recyclerview.widget.RecyclerView
|
||||||
|
android:id="@+id/recycler_view"
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="match_parent"
|
||||||
|
/>
|
||||||
|
|
||||||
|
<com.example.HomeContent.SmileView
|
||||||
|
android:id="@+id/smile_view"
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="match_parent" />
|
||||||
|
</RelativeLayout>
|
@ -0,0 +1,67 @@
|
|||||||
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
|
<androidx.cardview.widget.CardView xmlns:android="http://schemas.android.com/apk/res/android"
|
||||||
|
android:layout_width="321dp"
|
||||||
|
android:layout_height="456dp"
|
||||||
|
xmlns:app="http://schemas.android.com/apk/res-auto"
|
||||||
|
android:layout_gravity="center_horizontal"
|
||||||
|
app:cardCornerRadius="5dp"
|
||||||
|
app:elevation="10dp"
|
||||||
|
>
|
||||||
|
<RelativeLayout
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="match_parent">
|
||||||
|
|
||||||
|
<ImageView
|
||||||
|
android:id="@+id/img_bg"
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="match_parent"
|
||||||
|
android:scaleType="centerCrop"
|
||||||
|
android:layout_above="@+id/rela_bottom"
|
||||||
|
/>
|
||||||
|
<TextView
|
||||||
|
android:id="@+id/tv_title"
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:gravity="center_horizontal"
|
||||||
|
android:textColor="@android:color/white"
|
||||||
|
android:textStyle="bold"
|
||||||
|
android:layout_marginTop="16dp"
|
||||||
|
android:textSize="30sp"
|
||||||
|
/>
|
||||||
|
<RelativeLayout
|
||||||
|
android:id="@+id/rela_bottom"
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="56dp"
|
||||||
|
android:layout_alignParentBottom="true"
|
||||||
|
android:background="@android:color/white"
|
||||||
|
>
|
||||||
|
<de.hdodenhof.circleimageview.CircleImageView
|
||||||
|
android:id="@+id/img_user"
|
||||||
|
android:layout_width="35dp"
|
||||||
|
android:layout_height="35dp"
|
||||||
|
android:layout_centerVertical="true"
|
||||||
|
android:layout_marginLeft="16dp"
|
||||||
|
app:civ_border_overlay="true"
|
||||||
|
android:elevation="3dp"
|
||||||
|
/>
|
||||||
|
<TextView
|
||||||
|
android:id="@+id/tv_user_say"
|
||||||
|
android:layout_width="wrap_content"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:textStyle="bold"
|
||||||
|
android:layout_centerVertical="true"
|
||||||
|
android:layout_toRightOf="@+id/img_user"
|
||||||
|
android:layout_marginLeft="10dp"
|
||||||
|
android:layout_marginRight="16dp"
|
||||||
|
android:singleLine="true"
|
||||||
|
/>
|
||||||
|
</RelativeLayout>
|
||||||
|
<View
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="1px"
|
||||||
|
android:background="#b2b2b2"
|
||||||
|
android:layout_alignParentBottom="true"
|
||||||
|
/>
|
||||||
|
</RelativeLayout>
|
||||||
|
|
||||||
|
</androidx.cardview.widget.CardView>
|
Loading…
Reference in new issue