@@ -54,6 +54,7 @@ public class TextGroupView extends LinearLayout {
54
54
private TextView centerTextView ;
55
55
private TextView rightTextView ;
56
56
private EditText editView ;
57
+ private ImageView centerImageView ;
57
58
private ImageView rightImageView ;
58
59
59
60
private int allTextColor ;
@@ -161,6 +162,24 @@ public class TextGroupView extends LinearLayout {
161
162
private int editPaddingRight ;
162
163
private int editPaddingBottom ;
163
164
165
+
166
+ //中间图片控件属性
167
+ private int centerImageSrc ;
168
+ private int centerImageBackground ;
169
+ private int centerImageWidth ;
170
+ private int centerImageHeight ;
171
+ private int centerImageScaleType ;
172
+ private int centerImageMargin ;
173
+ private int centerImageMarginLeft ;
174
+ private int centerImageMarginTop ;
175
+ private int centerImageMarginRight ;
176
+ private int centerImageMarginBottom ;
177
+ private int centerImagePadding ;
178
+ private int centerImagePaddingLeft ;
179
+ private int centerImagePaddingTop ;
180
+ private int centerImagePaddingRight ;
181
+ private int centerImagePaddingBottom ;
182
+
164
183
//右边图片控件属性
165
184
private int rightImageSrc ;
166
185
private int rightImageBackground ;
@@ -355,6 +374,22 @@ private void initAttrs(Context context, AttributeSet attrs) {
355
374
editPaddingTop = typedArray .getDimensionPixelOffset (R .styleable .TextGroupView_edit_paddingTop , 0 );
356
375
editPaddingRight = typedArray .getDimensionPixelOffset (R .styleable .TextGroupView_edit_paddingRight , 0 );
357
376
editPaddingBottom = typedArray .getDimensionPixelOffset (R .styleable .TextGroupView_edit_paddingBottom , 0 );
377
+ //中间边图片
378
+ centerImageSrc = typedArray .getResourceId (R .styleable .TextGroupView_center_imageSrc , 0 );
379
+ centerImageBackground = typedArray .getResourceId (R .styleable .TextGroupView_center_imageBackground , 0 );
380
+ centerImageWidth = typedArray .getLayoutDimension (R .styleable .TextGroupView_center_imageWidth , LayoutParams .WRAP_CONTENT );
381
+ centerImageHeight = typedArray .getLayoutDimension (R .styleable .TextGroupView_center_imageHeight , LayoutParams .WRAP_CONTENT );
382
+ centerImageScaleType = typedArray .getInt (R .styleable .TextGroupView_center_imageScaleType , 0 );
383
+ centerImageMargin = typedArray .getDimensionPixelOffset (R .styleable .TextGroupView_center_imageMargin , 0 );
384
+ centerImageMarginLeft = typedArray .getDimensionPixelOffset (R .styleable .TextGroupView_center_imageMarginLeft , 0 );
385
+ centerImageMarginTop = typedArray .getDimensionPixelOffset (R .styleable .TextGroupView_center_imageMarginTop , 0 );
386
+ centerImageMarginRight = typedArray .getDimensionPixelOffset (R .styleable .TextGroupView_center_imageMarginRight , 0 );
387
+ centerImageMarginBottom = typedArray .getDimensionPixelOffset (R .styleable .TextGroupView_right_imageMarginBottom , 0 );
388
+ centerImagePadding = typedArray .getDimensionPixelOffset (R .styleable .TextGroupView_center_imagePadding , 0 );
389
+ centerImagePaddingLeft = typedArray .getDimensionPixelOffset (R .styleable .TextGroupView_center_imagePaddingLeft , 0 );
390
+ centerImagePaddingTop = typedArray .getDimensionPixelOffset (R .styleable .TextGroupView_center_imagePaddingTop , 0 );
391
+ centerImagePaddingRight = typedArray .getDimensionPixelOffset (R .styleable .TextGroupView_center_imagePaddingRight , 0 );
392
+ centerImagePaddingBottom = typedArray .getDimensionPixelOffset (R .styleable .TextGroupView_center_imagePaddingBottom , 0 );
358
393
//右边边图片
359
394
rightImageSrc = typedArray .getResourceId (R .styleable .TextGroupView_right_imageSrc , 0 );
360
395
rightImageBackground = typedArray .getResourceId (R .styleable .TextGroupView_right_imageBackground , 0 );
@@ -375,7 +410,7 @@ private void initAttrs(Context context, AttributeSet attrs) {
375
410
setBackground ();
376
411
//设置内容对齐方式
377
412
setGravity (Gravity .CENTER_VERTICAL );
378
- //添加视图(ImageView + TextView +TextView + EditText + ImageView)
413
+ //添加视图(ImageView + TextView +TextView + EditText + ImageView + ImageView )
379
414
leftImageView = new ImageView (context );
380
415
leftImageView .setLayoutParams (new LayoutParams (LayoutParams .WRAP_CONTENT , LayoutParams .WRAP_CONTENT ));
381
416
addView (leftImageView );
@@ -391,6 +426,9 @@ private void initAttrs(Context context, AttributeSet attrs) {
391
426
editView = new EditText (context );
392
427
editView .setLayoutParams (new LayoutParams (LayoutParams .WRAP_CONTENT , LayoutParams .MATCH_PARENT ));
393
428
addView (editView );
429
+ centerImageView = new ImageView (context );
430
+ centerImageView .setLayoutParams (new LayoutParams (LayoutParams .WRAP_CONTENT , LayoutParams .WRAP_CONTENT ));
431
+ addView (centerImageView );
394
432
rightImageView = new ImageView (context );
395
433
rightImageView .setLayoutParams (new LayoutParams (LayoutParams .WRAP_CONTENT , LayoutParams .WRAP_CONTENT ));
396
434
addView (rightImageView );
@@ -445,6 +483,12 @@ private void initAttrs(Context context, AttributeSet attrs) {
445
483
editView .setTextColor (editTextColor );
446
484
editView .setTextSize (TypedValue .COMPLEX_UNIT_PX , editTextSize );
447
485
editView .setGravity (editGravity );
486
+ //中间图标
487
+ setMarginPaddingWeight (centerImageView , centerImageMargin , centerImageMarginLeft , centerImageMarginTop , centerImageMarginRight , centerImageMarginBottom , centerImagePadding , centerImagePaddingLeft , centerImagePaddingTop , centerImagePaddingRight , centerImagePaddingBottom , -1 );
488
+ centerImageView .setImageResource (centerImageSrc );
489
+ centerImageView .setBackgroundResource (centerImageBackground );
490
+ centerImageView .setScaleType (scaleTypes [centerImageScaleType ]);
491
+ setParams (centerImageView , centerImageWidth , centerImageHeight );
448
492
//右边图标
449
493
setMarginPaddingWeight (rightImageView , rightImageMargin , rightImageMarginLeft , rightImageMarginTop , rightImageMarginRight , rightImageMarginBottom , rightImagePadding , rightImagePaddingLeft , rightImagePaddingTop , rightImagePaddingRight , rightImagePaddingBottom , -1 );
450
494
rightImageView .setImageResource (rightImageSrc );
@@ -1772,4 +1816,145 @@ public void setRightImagePaddingBottom(int rightImagePaddingBottom) {
1772
1816
this .rightImagePaddingBottom = rightImagePaddingBottom ;
1773
1817
setPadding (rightImageView , rightImagePadding , rightTextPaddingLeft , rightImagePaddingTop , rightTextPaddingRight , rightImagePaddingBottom );
1774
1818
}
1819
+
1820
+ public int getCenterImageSrc () {
1821
+ return centerImageSrc ;
1822
+ }
1823
+
1824
+ public void setCenterImageSrc (int centerImageSrc ) {
1825
+ this .centerImageSrc = centerImageSrc ;
1826
+ centerImageView .setImageResource (centerImageSrc );
1827
+ }
1828
+
1829
+ public int getCenterImageBackground () {
1830
+ return centerImageBackground ;
1831
+ }
1832
+
1833
+ public void setCenterImageBackground (int centerImageBackground ) {
1834
+ this .centerImageBackground = centerImageBackground ;
1835
+ centerImageView .setBackgroundResource (centerImageBackground );
1836
+ }
1837
+
1838
+ public int getCenterImageWidth () {
1839
+ return centerImageWidth ;
1840
+ }
1841
+
1842
+ public void setCenterImageWidth (int centerImageWidth ) {
1843
+ this .centerImageWidth = centerImageWidth ;
1844
+ setParams (centerImageView , centerImageWidth , centerImageHeight );
1845
+ }
1846
+
1847
+ public int getCenterImageHeight () {
1848
+ return centerImageHeight ;
1849
+ }
1850
+
1851
+ public void setCenterImageHeight (int centerImageHeight ) {
1852
+ this .centerImageHeight = centerImageHeight ;
1853
+ setParams (centerImageView , centerImageWidth , centerImageHeight );
1854
+ }
1855
+
1856
+ public ImageView .ScaleType getCenterImageScaleType () {
1857
+ return scaleTypes [centerImageScaleType ];
1858
+ }
1859
+
1860
+ public void setCenterImageScaleType (ImageView .ScaleType scaleType ) {
1861
+ for (int i = 0 ; i < scaleTypes .length ; i ++) {
1862
+ if (scaleTypes [i ] == scaleType ) {
1863
+ this .centerImageScaleType = i ;
1864
+ }
1865
+ }
1866
+ centerImageView .setScaleType (scaleType );
1867
+ }
1868
+
1869
+ public int getCenterImageMargin () {
1870
+ return centerImageMargin ;
1871
+ }
1872
+
1873
+ public void setCenterImageMargin (int centerImageMargin ) {
1874
+ this .centerImageMargin = centerImageMargin ;
1875
+ setMargin (centerImageView , centerImageMargin , centerImageMarginLeft , centerImageMarginTop , centerImageMarginRight , centerImageMarginBottom );
1876
+ }
1877
+
1878
+ public int getCenterImageMarginLeft () {
1879
+ return centerImageMarginLeft ;
1880
+ }
1881
+
1882
+ public void setCenterImageMarginLeft (int centerImageMarginLeft ) {
1883
+ this .centerImageMarginLeft = centerImageMarginLeft ;
1884
+ setMargin (centerImageView , centerImageMargin , centerImageMarginLeft , centerImageMarginTop , centerImageMarginRight , centerImageMarginBottom );
1885
+ }
1886
+
1887
+ public int getCenterImageMarginTop () {
1888
+ return centerImageMarginTop ;
1889
+ }
1890
+
1891
+ public void setCenterImageMarginTop (int centerImageMarginTop ) {
1892
+ this .centerImageMarginTop = centerImageMarginTop ;
1893
+ setMargin (centerImageView , centerImageMargin , centerImageMarginLeft , centerImageMarginTop , centerImageMarginRight , centerImageMarginBottom );
1894
+ }
1895
+
1896
+ public int getCenterImageMarginCenter () {
1897
+ return centerImageMarginRight ;
1898
+ }
1899
+
1900
+ public void setCenterImageMarginCenter (int centerImageMarginRight ) {
1901
+ this .centerImageMarginRight = centerImageMarginRight ;
1902
+ setMargin (centerImageView , centerImageMargin , centerImageMarginLeft , centerImageMarginTop , centerImageMarginRight , centerImageMarginBottom );
1903
+ }
1904
+
1905
+ public int getCenterImageMarginBottom () {
1906
+ return centerImageMarginBottom ;
1907
+ }
1908
+
1909
+ public void setCenterImageMarginBottom (int centerImageMarginBottom ) {
1910
+ this .centerImageMarginBottom = centerImageMarginBottom ;
1911
+ setMargin (centerImageView , centerImageMargin , centerImageMarginLeft , centerImageMarginTop , centerImageMarginRight , centerImageMarginBottom );
1912
+ }
1913
+
1914
+ public int getCenterImagePadding () {
1915
+ return centerImagePadding ;
1916
+ }
1917
+
1918
+ public void setCenterImagePadding (int centerImagePadding ) {
1919
+ this .centerImagePadding = centerImagePadding ;
1920
+ setPadding (centerImageView , centerImagePadding , centerTextPaddingLeft , centerImagePaddingTop , centerTextPaddingRight , centerImagePaddingBottom );
1921
+ }
1922
+
1923
+ public int getCenterImagePaddingLeft () {
1924
+ return centerImagePaddingLeft ;
1925
+ }
1926
+
1927
+ public void setCenterImagePaddingLeft (int centerImagePaddingLeft ) {
1928
+ this .centerImagePaddingLeft = centerImagePaddingLeft ;
1929
+ setPadding (centerImageView , centerImagePadding , centerTextPaddingLeft , centerImagePaddingTop , centerTextPaddingRight , centerImagePaddingBottom );
1930
+ }
1931
+
1932
+ public int getCenterImagePaddingTop () {
1933
+ return centerImagePaddingTop ;
1934
+ }
1935
+
1936
+ public void setCenterImagePaddingTop (int centerImagePaddingTop ) {
1937
+ this .centerImagePaddingTop = centerImagePaddingTop ;
1938
+ setPadding (centerImageView , centerImagePadding , centerTextPaddingLeft , centerImagePaddingTop , centerTextPaddingRight , centerImagePaddingBottom );
1939
+ }
1940
+
1941
+ public int getCenterImagePaddingRight () {
1942
+ return centerImagePaddingRight ;
1943
+ }
1944
+
1945
+ public void setCenterImagePaddingRight (int centerImagePaddingRight ) {
1946
+ this .centerImagePaddingRight = centerImagePaddingRight ;
1947
+ setPadding (centerImageView , centerImagePadding , centerTextPaddingLeft , centerImagePaddingTop , centerTextPaddingRight , centerImagePaddingBottom );
1948
+ }
1949
+
1950
+ public int getCenterImagePaddingBottom () {
1951
+ return centerImagePaddingBottom ;
1952
+ }
1953
+
1954
+ public void setCenterImagePaddingBottom (int centerImagePaddingBottom ) {
1955
+ this .centerImagePaddingBottom = centerImagePaddingBottom ;
1956
+ setPadding (centerImageView , centerImagePadding , centerTextPaddingLeft , centerImagePaddingTop , centerTextPaddingRight , centerImagePaddingBottom );
1957
+ }
1958
+
1959
+
1775
1960
}
0 commit comments