• fragment在水平/垂直时的应用


    直接看代码

     1 public class MainActivity extends Activity {
     2 
     3     @Override
     4     protected void onCreate(Bundle savedInstanceState) {
     5         super.onCreate(savedInstanceState);
     6         setContentView(R.layout.activity_main);
     7 
     8 /*        Fragment1 fragment1 = new Fragment1();
     9         Fragment2 fragment2 = new Fragment2();
    10 
    11         FragmentManager fragmentManager = getFragmentManager();
    12         FragmentTransaction fragmentTransaction = fragmentManager.beginTransaction();
    13         fragmentTransaction.add(R.id.mainLayout, fragment1, "fragment1");
    14         fragmentTransaction.add(R.id.mainLayout, fragment2, "fragment2");
    15 
    16         fragmentTransaction.commit();*/
    17 
    18         Point size = new Point();
    19         this.getWindowManager().getDefaultDisplay().getSize(size);
    20         int width = size.x;
    21         int height = size.y;
    22         if (width > height) {//比较显示窗口的长宽
    23             Fragment1 fragment1 = new Fragment1();
    24             getFragmentManager().beginTransaction().replace(R.id.mainLayout, fragment1).commit();
    25         } else {
    26             Fragment2 fragment2 = new Fragment2();
    27             getFragmentManager().beginTransaction().replace(R.id.mainLayout, fragment2).commit();
    28         }
    29     }
    30 }

    另外如下方法已经被谷歌deprecated

    1 Display display = getWindowManager().getDefaultDisplay();  
    2         if (display.getWidth() > display.getHeight()) {  
    3             Fragment1 fragment1 = new Fragment1();  
    4             getFragmentManager().beginTransaction().replace(R.id.main_layout, fragment1).commit();  
    5         } else {  
    6             Fragment2 fragment2 = new Fragment2();  
    7             getFragmentManager().beginTransaction().replace(R.id.main_layout, fragment2).commit();  
    8         } 
  • 相关阅读:
    php的冒泡算法
    mysql 处理重复数据
    Ehcache配置详解及CacheManager使用
    JFinal常见问题和知识点笔记
    JFinal连接数据库配置说明
    innerHTML和innerText区分
    方法$.data()和$.('#test').on()的使用
    input text的所有事件
    jQuery操作Select
    在js或css后加?v= 版本号不让浏览器缓存
  • 原文地址:https://www.cnblogs.com/turtle920/p/4898369.html
Copyright © 2020-2023  润新知