1
위젯이 있습니다. 및 그 안에 이미지보기; 프로그래밍 방식으로 ImageView의 크기를 가져 오거나 설정하려고합니다. 그리고 relativeLayout과 같은 다른보기를 위해 이렇게 ..... 어떻게 할 수 있습니까? 감사합니다.프로그래밍 방식으로 안드로이드 위젯 이미지보기 크기를 가져 오거나 설정하십시오.
위젯이 있습니다. 및 그 안에 이미지보기; 프로그래밍 방식으로 ImageView의 크기를 가져 오거나 설정하려고합니다. 그리고 relativeLayout과 같은 다른보기를 위해 이렇게 ..... 어떻게 할 수 있습니까? 감사합니다.프로그래밍 방식으로 안드로이드 위젯 이미지보기 크기를 가져 오거나 설정하십시오.
**get the width and height of an android.widget.ImageView**
int finalHeight, finalWidth;
final ImageView iv = (ImageView)findViewById(R.id.scaled_image);
final TextView tv = (TextView)findViewById(R.id.size_label);
ViewTreeObserver vto = iv.getViewTreeObserver();
vto.addOnPreDrawListener(new ViewTreeObserver.OnPreDrawListener() {
public boolean onPreDraw() {
iv.getViewTreeObserver().removeOnPreDrawListener(this);
finalHeight = iv.getMeasuredHeight();
finalWidth = iv.getMeasuredWidth();
tv.setText("Height: " + finalHeight + " Width: " + finalWidth);
return true;
}
});
// if not declare in xml layout
myImageView.setLayoutParams(new ViewGroup.LayoutParams(
ViewGroup.LayoutParams.WRAP_CONTENT,
ViewGroup.LayoutParams.WRAP_CONTENT));
**Set ImageView width and height programmatically**
image_view.getLayoutParams().height = 20;
감사합니다. 하지만 findViewById가 없습니다 :( –
LinearLayout.LayoutParams layoutParams = new LinearLayout.LayoutParams (30, 30); myImageView.setLayoutParams (layoutParams); –
위젯에서 어떻게 imageview를 찾을 수 있습니까? –