Screen orientation For tablets And devices
I am using the same code for both tablets as well as device,Here is my problem while coming to mobile in both orientation it should load list view, coming to tablet in portrait it need to load listview and then coming to landscape it should load gridview?
Thanks
I have used this code any one can help me plz..
Configuration config = getResources().getConfiguration();
if((config.screenLayout & Configuration.ORIENTATION_LANDSCAPE) ==
Configuration.SCREENLAYOUT_SIZE_XLARGE));
{
开发者_StackOverflow中文版 this.gridView();
}else{
this.listview();
}
If you're using xml for your layouts, all you need to do is create different xml files and place them in the layout folder with appropriate configuration qualifier. See this article for details.
For you, you would use the following folders:
res/layout/my_layout.xml // layout for normal screen size ("default"). Listview here
res/layout-xlarge-land/my_layout.xml // layout for extra large in landscape orientation. Gallery here
Remember, you need to create these folders if they don't exist.
In your code, if you call setContentView(R.id.my_layout)
, android will use the appropriate layout. Then, you can do a findViewById()
call where it should return null for the view of the layout not being used. You can do a findViewById()
on both the ListView and GridView. Based on which view returns null, you can set the member (this.gridView or this.listView) appropriately.
精彩评论