Android ImageView高度始终为0
我正在尝试获取imageview的高度和宽度,以便可以将图像缩小到适当的大小,但每次尝试获取高度时,高度都为0。我想可能它还没有被测量,所以我在imageview上放置了一个Android ImageView高度始终为0,android,android-imageview,Android,Android Imageview,我正在尝试获取imageview的高度和宽度,以便可以将图像缩小到适当的大小,但每次尝试获取高度时,高度都为0。我想可能它还没有被测量,所以我在imageview上放置了一个on predrawListener,这样我就知道它会在那个时候被测量,但我仍然得到0,所以我不确定问题出在哪里 这是我的全部布局 <?xml version="1.0" encoding="utf-8"?> <RelativeLayout xmlns:android="http://schemas.an
on predrawListener
,这样我就知道它会在那个时候被测量,但我仍然得到0,所以我不确定问题出在哪里
这是我的全部布局
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_alignParentTop="true"
android:layout_alignParentLeft="true"
android:id="@+id/content"
android:layout_above="@+id/comment_layout">
<ImageView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="@+id/imageView"/>
<ListView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="@+id/comments"
android:background="@android:color/transparent"/>
</RelativeLayout>
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="@+id/comment_layout">
<EditText
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="@+id/editText"
android:layout_alignParentBottom="true"
android:layout_toLeftOf="@+id/send_button"/>
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/send_button"
android:layout_alignParentBottom="true"
android:layout_alignParentRight="true"/>
</RelativeLayout>
</RelativeLayout>
宽度显示为720,但高度始终显示为0
输入硬宽度也没有效果这应该适用于像这样的
OnGlobalLayoutListener
final ImageView image = new ImageView(this);
image.getViewTreeObserver().addOnGlobalLayoutListener(new OnGlobalLayoutListener() {
@Override
public void onGlobalLayout() {
// TODO Auto-generated method stub
int height = image.getHeight();
}
});
当全局布局状态或可见性更改时调用此回调检查这与使用
onPreDraw
有何不同?该视图应在该位置测量point@Vinayak.B它仍然给我0你可以检查高度后,分配给它的图像,然后它将是非零value@Chaitanya但这是我不能做到的,因为我需要尺寸,这样我就知道如何缩放全尺寸图像
final ImageView image = new ImageView(this);
image.getViewTreeObserver().addOnGlobalLayoutListener(new OnGlobalLayoutListener() {
@Override
public void onGlobalLayout() {
// TODO Auto-generated method stub
int height = image.getHeight();
}
});