一、组件设置setCompoundDrawables不生效解决办法
在代码中设置组件的drawable的时候如果单纯的使用setCompoundDrawables是不会有效果的,因为没有指定drawable的大小,即Bound,具体代码如下:
Drawable drawable = getResources().getDrawable(R.drawable.ic_et_bg);
drawable.setBounds(0, 0, drawable.getIntrinsicWidth(), drawable.getIntrinsicHeight());
mEt.setCompoundDrawables(drawable,null,null,null,null);
这种方式是可以指定drawable的大小的,还有另外一种方式,使用drawable的默认大小,如下:
Drawable drawable = getResources().getDrawable(R.drawable.ic_et_bg);
mEt.setCompoundDrawablesWithIntrinsicBounds(drawable,null,null,null,null);
二、关于LinearLayout的对齐
如果设置LinearLayout为android:orientation=”horizontal”,那设置子控件的android:layout_gravity = “left”或android:layout_gravity = “right”是没有效果的。
三、动态改变RecyclerView的高度
recyclerView.setLayoutManager(new LinearLayoutManager(getActivity()) {
@Override
public void onMeasure(RecyclerView.Recycler recycler, RecyclerView.State state, int widthSpec, int heightSpec) {
setMeasuredDimension(View.MeasureSpec.getSize(widthSpec),45*4+10*3);
}
});
四、RecyclerView 自动滑动到底部
mRecyclerView.scrollToPosition(adapter.getItemCount()-1);
五、Button的英文字符都变大写
1.在布局文件Button下增加android:textAllCaps=”false”
2.在代码中,mButton.setTransformationMethod(null)
3.既然是主题引起的,我们可以自定义Button主题
<style name="MyButton" parent="Widget.AppCompat.Button">
<item name="android:textAllCaps">false</item>
</style>
4.自定义Button
public class MyButton extends Button {
public Button(Context context, AttributeSet attrs) {
super(context, attrs);
setSupportAllCaps(false);
}
public Button(Context context, AttributeSet attrs, int defStyleAttr) {
super(context, attrs, defStyleAttr);
setSupportAllCaps(false);
}
}