如何修复 imageview ClassCaseException 的 LayoutParam?
这是我每次尝试为图像视图设置 LayoutParam 时遇到的错误。
10-02 03:27:53.081: ERROR/AndroidRuntime(1272): FATAL EXCEPTION: main
10-02 03:27:53.081: ERROR/AndroidRuntime(1272): java.lang.ClassCastException: android.widget.Gallery$LayoutParams
10-02 03:27:53.081: ERROR/AndroidRuntime(1272): at android.widget.LinearLayout.measureHorizontal(LinearLayout.java:659)
10-02 03:27:53.081: ERROR/AndroidRuntime(1272): at android.widget.LinearLayout.onMeasure(LinearLayout.java:311)
10-02 03:27:53.081: ERROR/AndroidRuntime(1272): at android.view.View.measure(View.java:8313)
10-02 03:27:53.081: ERROR/AndroidRuntime(1272): at android.view.ViewGroup.measureChild(ViewGroup.java:3109)
这是我的 imageview 布局,我试图为其设置布局参数。
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="wrap_content">
<ImageView
android:id="@+id/imageView"
android:layout_width="50dip"
android:layout_height="50dip" android:src="@drawable/stub" android:scaleType="centerCrop"/>
<TextView
android:id="@+id/text"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_weight="1" android:layout_gravity="left|center_vertical" android:textSize="20dip" android:layout_marginLeft="10dip"/>
</LinearLayout>
这是我膨胀视图然后尝试设置参数的代码,但我不断收到上面的错误。
public View getView(int position, View convertView, ViewGroup parent) {
View vi=convertView;
if(convertView==null)
vi = inflater.inflate(R.layout.lazyitemt, null);
ImageView image=(ImageView)vi.findViewById(R.id.imageView);
image.setLayoutParams(new Gallery.LayoutParams(150, 150));
imageLoader.DisplayImage(data[position], activity, image);
return vi;
}
我不知道为什么我一直收到这个。一切似乎都是对的?我该如何解决这个问题?
This is the error i get each time i try and set the LayoutParam's for a image view.
10-02 03:27:53.081: ERROR/AndroidRuntime(1272): FATAL EXCEPTION: main
10-02 03:27:53.081: ERROR/AndroidRuntime(1272): java.lang.ClassCastException: android.widget.Gallery$LayoutParams
10-02 03:27:53.081: ERROR/AndroidRuntime(1272): at android.widget.LinearLayout.measureHorizontal(LinearLayout.java:659)
10-02 03:27:53.081: ERROR/AndroidRuntime(1272): at android.widget.LinearLayout.onMeasure(LinearLayout.java:311)
10-02 03:27:53.081: ERROR/AndroidRuntime(1272): at android.view.View.measure(View.java:8313)
10-02 03:27:53.081: ERROR/AndroidRuntime(1272): at android.view.ViewGroup.measureChild(ViewGroup.java:3109)
Here is my layout with the imageview i am trying to set the layoutParam's for..
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="wrap_content">
<ImageView
android:id="@+id/imageView"
android:layout_width="50dip"
android:layout_height="50dip" android:src="@drawable/stub" android:scaleType="centerCrop"/>
<TextView
android:id="@+id/text"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_weight="1" android:layout_gravity="left|center_vertical" android:textSize="20dip" android:layout_marginLeft="10dip"/>
</LinearLayout>
And here is the code i inflate the view and then try to set the Param's but i keep getting the error above.
public View getView(int position, View convertView, ViewGroup parent) {
View vi=convertView;
if(convertView==null)
vi = inflater.inflate(R.layout.lazyitemt, null);
ImageView image=(ImageView)vi.findViewById(R.id.imageView);
image.setLayoutParams(new Gallery.LayoutParams(150, 150));
imageLoader.DisplayImage(data[position], activity, image);
return vi;
}
I dont know why i keep getting this. Everything seems to be right? How can i resolve this?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您将
imageView
放入 LinearLayout 中。所以,你应该像这样修改你的布局参数代码You put
imageView
inside LinearLayout. So, you should modify your layout param code like this