开发者

Add RelativeLayout or ListView inside Gallery View in Android?

开发者 https://www.devze.com 2023-01-15 08:43 出处:网络
Can开发者_运维问答 someone let me know how to add RelativeLayout or listview inside GalleryView. I have tried by returning listview or RelativeLayout from the adapter of Gallery but it gives ClassCast

Can开发者_运维问答 someone let me know how to add RelativeLayout or listview inside GalleryView. I have tried by returning listview or RelativeLayout from the adapter of Gallery but it gives ClassCastException java.lang.ClassCastException: android.widget.RelativeLayout$LayoutParams.

Can someone let me know how to go about it?


When you set the LayoutParams of a view, you need to use the specific LayoutParams of the parent view. In your case, you have to use Gallery.LayoutParams as shown here:

ListView listView = new ListView(cont);
listView.setLayoutParams(new Gallery.LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT));
0

精彩评论

暂无评论...
验证码 换一张
取 消