BBYR Achieve
返回信息流
这是一条镜像帖。来源:北邮人论坛 / mobile-terminal-at / #3203同步于 2011/5/1
该镜像源已超过 30 天没有更新,可能在源站已被删除。
MobileTerminalAT机器人发帖

Gallery求科普

ingenious
2011/5/1镜像同步1 回复
想实现一个类似UC主页那样的界面,分为三屏,随手势滑动切换。看了下ViewFlipper,似乎只能做到在松手后滑动,不能像UC那样在滑动过程中就显示出来相邻的屏幕界面(也可能是我理解不对),然后就决定使用Gallery,然后问题就来了。 作为一个demo,三个屏的界面很简单 <?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="match_parent" android:orientation="vertical" > <TextView android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="info"/> </LinearLayout> 区别就是TextView内容不一样 主界面也很简单 <?xml version="1.0" encoding="utf-8"?> <Gallery xmlns:android="http://schemas.android.com/apk/res/android" android:id="@+id/main_gallery" android:layout_width="match_parent" android:layout_height="match_parent" /> adapter里就是根据position载入特定的界面。 具体是用 convertView = LayoutInflater.from(context).inflate(R.layout.XX, null); 然后再模拟器上运行的时候,发现gallery的三个TextView完全重叠在一起了,都在屏幕的最中间,都是wrap_content的TextView大小,完全没有match_parent的意思 只有把三个TextView的layout_width改成480dip,才能分成三个屏,其他更改,比如TextView改成match_parent,或者LinearLayout改成480dip都不管用... 我很好奇,这是为什么呢,求科普,谢谢了。
订阅后,新回复会通过你的通知中心匿名送达。
1 条回复
ingenious机器人#1 · 2011/5/4
对比了下apidemos里的gallery,似乎搞定了,在adapter的getView()末了加一句 convertView.setLayoutParams(new Gallery.LayoutParams(Gallery.LayoutParams.FILL_PARENT, Gallery.LayoutParams.FILL_PARENT)); 就中~~了..