TextAndImgShowView.java
2.82 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
package com.shunzhi.parent.views;
import android.app.Activity;
import android.content.Context;
import android.support.annotation.DrawableRes;
import android.support.annotation.Nullable;
import android.util.AttributeSet;
import android.view.View;
import android.widget.FrameLayout;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;
import com.bumptech.glide.Glide;
import com.share.mvpsdk.utils.DisplayUtils;
import com.shunzhi.parent.AppConfig;
import com.shunzhi.parent.R;
/**
* Created by ToaHanDong on 2018/1/22.
*/
public class TextAndImgShowView extends LinearLayout {
public TextAndImgShowView(Context context) {
super(context);
init(context);
}
public TextAndImgShowView(Context context, @Nullable AttributeSet attrs) {
super(context, attrs);
init(context);
}
public TextAndImgShowView(Context context, @Nullable AttributeSet attrs, int defStyleAttr) {
super(context, attrs, defStyleAttr);
init(context);
}
ImageView image;
TextView text;
FrameLayout layout;
int[] imgs = null;
boolean isSelect = false;
private void init(Context context) {
View view = View.inflate(context, R.layout.text_and_img_show, this);
image = view.findViewById(R.id.image);
text = view.findViewById(R.id.text);
layout = view.findViewById(R.id.layout);
}
public void setImgs(@DrawableRes int normalDrawable, @DrawableRes int selectDrawable) {
imgs = new int[]{normalDrawable, selectDrawable};
}
public void addImgs(String imgUrl){
// Log.d("66666","imgUrl="+imgUrl);
if (!imgUrl.startsWith("http"))imgUrl= AppConfig.BASE_URL_FILE+imgUrl;
Glide.with(getContext()).load(imgUrl).error(R.drawable.gxzt).into(image);
}
public void setSelect(boolean isSelect) {
if (isSelect) {
if (imgs != null && imgs.length > 1)
image.setImageResource(imgs[1]);
} else {
if (imgs != null && imgs.length > 1)
image.setImageResource(imgs[0]);
}
}
public void setText(String content) {
text.setText(content);
}
public void setTextColor(int color) {
text.setTextColor(color);
}
public void setWidth(Activity activity, View layout_control) {
// Log.d("66666", "layout_control=" + layout_control.getMeasuredWidth());
LayoutParams params = new LayoutParams(LayoutParams.MATCH_PARENT,LayoutParams.MATCH_PARENT);
params.width = (DisplayUtils.getScreenWidthPixels(activity) -
DisplayUtils.dp2px(layout_control.getPaddingLeft() + layout_control.getPaddingRight()
)) / 4;
layout.setLayoutParams(params);
LayoutParams params1 = new LayoutParams(52,52);
image.setLayoutParams(params1);
}
}