我为Android的ImageView创建了以下自定义本机组件。
public class ImageViewManager extends SimpleViewManager<ImageView> {
public static final String REACT_CLASS = "ImageView";
@Override
public String getName() {
return REACT_CLASS;
}
@Override
protected ImageView createViewInstance(ThemedReactContext reactContext) {
ImageView imageView = new ImageView(reactContext);
imageView.setLayoutParams(new GridView.LayoutParams(300, 200))
return imageView;
}
@ReactProp(name="src")
public void setSrc(ImageView imageView, String src) {
try {
Bitmap bm = ImageUtilConverter.convert(src); // base64 to bitmap
imageView.setImageBitmap(bm);
} catch(IllegalArgumentException e) {
}
}
}
在JavaScript中: 从“ ./ImageView”导入ImageView
<ImageView
style={{width: deviceWidth, height: deviceHeight}}
src={this.state.selected} // base64 data
/>
现在,我想获取Java中组件的高度和宽度,以便可以在imageView.setLayoutParams(new GridView.LayoutParams(300,200))中设置高度和宽度。
是否可以用Java获取组件大小?