• Android连载10-动态添加页面、创建一个新闻app


    一、动态规划界面的大小

    1.我们在res的文件夹里面创建一个新的文件夹large_fragment用来,然后写一个界面,activity_main.xml文件,用于存储平板电脑等一些分辨率高的界面。也就是说小屏幕使用正常activity_main文件、大屏幕就使用large_fragment文件夹里面的界面。

     
    
    <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    
        xmlns:tools="http://schemas.android.com/tools"
    
        android:layout_width="match_parent"
    
        android:layout_height="match_parent" ><fragment
    
            android:id="@+id/left_fragment"
    
            android:name="com.example.fragmenttest.LeftFragment"
    
            android:layout_height="match_parent"
    
            android:layout_width="match_parent" />
    
    ​
    
    ​
    
    </LinearLayout>
     
    
    <?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" >
    
       
    
        <fragment
    
            android:id="@+id/left_fragment"
    
            android:name="com.example.fragmenttest.LeftFragment"
    
            android:layout_width="0dp"
    
            android:layout_height="match_parent"
    
            android:layout_weight="1" />
    
       
    
        <fragment
    
            android:id="@+id/right_fragment"
    
            android:name="com.example.fragmenttest.RightFragment"
    
            android:layout_width="0dp"
    
            android:layout_height="match_parent"
    
            android:layout_weight="3" />
    
       
    
    </LinearLayout>

    二、精准选择界面

    1.我们在res下面建一个文件夹layout-sw600dp,这个就意味着如果屏幕的宽度小于600dp的时候,则会默认加载这个文件夹下面的activity_main​界面。

    <?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" >
    
       
    
        <fragment
    
            android:id="@+id/left_fragment"
    
            android:name="com.example.fragment.LeftFragment"
    
            android:layout_width="0dp"
    
            android:layout_height="match_parent"
    
            android:layout_weight="1" />
    
           
    
        <fragment
    
            android:id="@+id/right_fragment"
    
            android:name="com.example,fragmenttest.RightFragment"
    
            android:layout_width="0dp"
    
            android:layout_height="match_parent"
    
            android:layout_weight="3" />
    
       
    
    </LinearLayout>

    三、我们在编写app的时候总不能需要维护两套代码,但是我们接下来将会探究如果能够编写一个同时兼容电脑和手机的app​。

    我们建立一个新闻的app,下面先写一个新闻类,具体的细节我们下次在写。​

    package com.example.fragmentbestpractice;
    
    ​
    
    public class News {
    
     
    
      private String title;
    
     
    
      private String content;
    
    ​
    
      public String getTitle() {
    
        return title;
    
      }
    
    ​
    
      public void setTitle(String title) {
    
        this.title = title;
    
      }
    
    ​
    
      public String getContent() {
    
        return content;
    
      }
    
    ​
    
      public void setContent(String content) {
    
        this.content = content;
    
      }
    
     
    
    }

    三、源码:

    1.项目地址

    https://github.com/ruigege66/Android/tree/master/FragmentTest

    2.CSDN:https://blog.csdn.net/weixin_44630050

    3.博客园:https://www.cnblogs.com/ruigege0000/

    4.欢迎关注微信公众号:傅里叶变换,个人公众号,仅用于学习交流,后台回复”礼包“,获取大数据学习资料

     

  • 相关阅读:
    [Effective C++, 学习总结] 01 视C++为一个语言联邦
    【原创】从“心”开始
    [C++, Basic, 02] 控制对象初始化与析构的顺序
    电信PPPoE拨号失败,获取不到IP
    IPV6学习笔记
    win10提示目前无法访问SmartScreen
    IBM服务器进入IMM
    python把文字转成语音
    python爬虫获取贴吧图片
    ibm x3550更换主板后无法加载系统引导
  • 原文地址:https://www.cnblogs.com/ruigege0000/p/12879849.html
Copyright © 2020-2023  润新知