I have my own custom component in xml written like this
<com.app.components.CustomComponent
android:id="@+id/component"
android:layout_width="96dp"
android:layout_height="96dp"
android:scaleType="fitCenter"/>
Attrs:
<declare-styleable name="CustomComponent">
<attr name="android:scaleType"/>
</declare-styleable>
My custom component constructor looks like this
@Bind(R.id.imageView) ImageView imageView;
@Bind(R.id.progressBar) ProgressBar progressBar;
public CustomComponent(Context context, AttributeSet attrs) {
super(context, attrs);
TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.FunGuideImageView, 0, 0);
// how to correctly get scale type defined in xml ?
int scaleType = a.getValue(R.styleable.CustomComponent_android_scaleType,
ImageView.ScaleType);
LayoutInflater inflater = (LayoutInflater) context
.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
View view = inflater.inflate(R.layout.imageview, this, true);
ButterKnife.bind(view);
imageView.setScaleType( scaleType );
}
How can I get the scaleType defined in xml and set it to my imageView?
CustomComponentbeing extendingView?ImageView, you can simply dogetScaleType(), otherwise, I don't think making your styleables the same names as theandroid:attributes is a good idea.