medyo / Fancybuttons

Icons, Borders, Radius ... for Android buttons
1.77k stars 397 forks source link

关于setGravity和drawableTop&Left&Right&Bottom的问题 #72

Closed Hiboboo closed 6 years ago

Hiboboo commented 7 years ago

第一个问题,我发现setGravity或者setTextGravity这个方法并不起作用,原因透过源码发现,在你代码的 setupTextView()方法中textView.setLayoutParams(new LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT));调用有些问题。布局的宽高属性设置不当导致,new LayoutParams(width, height)其中width的值改为MATCH_PARENT即可解决该问题。 第二个问题,透过源码看到,是用的TextView进行的内部实现,那么,是否可以将该控件的drawableLeft,drawableTop,drawableRight,drawableBottom四个属性加入进来?

medyo commented 7 years ago

嗨 @Hiboboo ,你能用英语写吗?

daiwenbo88 commented 7 years ago

What he means: The first question, I found the setGravity or setTextGravity this method does not work, because through the source, found that in your codeSetupTextView () method of textView. SetLayoutParams (new LayoutParams (LayoutParams. WRAP_CONTENT, LayoutParams. WRAP_CONTENT));There are some problems with calls.The layout of the high property is set properly, wide, new LayoutParams (width, height) in which the width to change the value of MATCH_PARENT can solve the problem.The second question, see, through the source code is to use the internal implementation TextView, so, whether the control can be drawableLeft, drawableTop, drawableRight, drawableBottom four attributes to join in?

medyo commented 7 years ago

Hi @daiwenbo88, @Hiboboo

Question 1 : setTextGravity(int) works perfectly, it's about to define text alignment, not its position. By using MATCH_PARENT the icon won't be visible if the nested view has an horizontal orientation, So I think WRAP_CONTENT will fit all the cases

Question 2 : I used a custom view instead of the native textView Drawable to get more control of customization, for example using font icons, handling padding correctly ...

F0RIS commented 7 years ago

@medyo I must to say that I agree with @Haegon about gravity, because when I involved FancyButton in my big project I had issues with vertical gravity of text inside button with strictly defined height. So I set TextView's height to MATCH_PARENT and delete some paddings (to fix text cutting) in the code and it solved my problems. Now in my project I have FancyButton with a lot of changes, but I will try later to use version from repo to determine exactly what should be better to change/fix.