例如:
实际上我使用了一个名为daily.xml的视图.这个视图包含一个翻页器,如果用户需要,它将以编程方式填充5个ListVIEws来翻转.
<?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="fill_parent"androID:orIEntation="vertical"androID:background="@drawable/background"> <de.oszimtcc.timetablevIEw.TimetableFlipperVIEw androID:ID="@+ID/flipper" androID:layout_wIDth="match_parent" androID:layout_height="fill_parent" androID:layout_margin="20dp" androID:background="@androID:color/transparent" androID:cachecolorHint="@androID:color/transparent" > </de.oszimtcc.timetablevIEw.TimetableFlipperVIEw></linearLayout>
TimetableScreen.java中的翻转器
activity.setContentVIEw(R.layout.daily); Log.i(TimetableApplication.LOG_TAG,"Start create Timetable-Aplication"); activity.setContentVIEw(R.layout.daily); activity.inflater = LayoutInflater.from(this.activity); flipper = (TimetableFlipperVIEw) activity.findVIEwByID(R.ID.flipper); dayListVIEw = (ListVIEw) activity.findVIEwByID(R.ID.dayListVIEw); flipper.AddContent(**Content to show **);
现在,我想添加一个landscapemode.在这些模式中,我不会hava这样的鳍状肢,因为有足够的空间在水平线性布局上显示所有ListVIEws.所以我创建了一个布局 – 土地资源 – 文件夹,每天添加另一个. XML
<?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="fill_parent"androID:orIEntation="horizontal"androID:background="@drawable/background"><de.oszimtcc.timetablevIEw.BlockListVIEw androID:ID="@+ID/dayListVIEwMonday" androID:layout_wIDth="wrap_content" androID:layout_height="match_parent" androID:padding="5dp" androID:ListSelector="@drawable/day_selector" androID:background="@androID:color/transparent"androID:cachecolorHint="@androID:color/transparent"></de.oszimtcc.timetablevIEw.BlockListVIEw>...the same ListVIEw again for 4 times,with different androID:ID...</linearLayout>
但是如何处理我的TimetableScreen.java类呢?因为没有鳍状肢我不能使用我的默认构造函数来初始化类.我应该在每次调用onCreate时调用不同的方法,还是有更好的可能性处理它?
非常感谢Kooki!
解决方法 你可以使用getResources().getConfiguration().orIEntation,以找出屏幕方向.如果是横向模式,请不要初始化鳍状肢变量.我刚在代码中添加了一行,检查if控制语句.
activity.setContentVIEw(R.layout.daily);Log.i(TimetableApplication.LOG_TAG,"Start create Timetable-Aplication");activity.setContentVIEw(R.layout.daily); if(getResources().getConfiguration().orIEntation == Configuration.ORIENTATION_POTRAIT) { //Check this statementactivity.inflater = LayoutInflater.from(this.activity); flipper = (TimetableFlipperVIEw) activity.findVIEwByID(R.ID.flipper); dayListVIEw = (ListVIEw) activity.findVIEwByID(R.ID.dayListVIEw);flipper.AddContent(**Content to show **);} else {//Code for Landscape mode}总结
以上是内存溢出为你收集整理的android – 不同的屏幕方向全部内容,希望文章能够帮你解决android – 不同的屏幕方向所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)