Android serial 10- add pages dynamically and create a news app

1, Size of dynamic planning interface 1. We create a new ...

1, Size of dynamic planning interface

1. We create a new folder large fragment in the res folder, and then write an interface, activity main.xml file, to store some high-resolution interfaces such as tablet computers. That is to say, the small screen uses the normal activity main file, and the large screen uses the interface in the large fragment folder.

<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>

2, Precise selection interface

1. We create a folder layout-sw600dp under res, which means that if the screen width is less than 600dp, the activity main interface under the folder will be loaded by default.

<?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>

3, We can't always maintain two sets of code when we write apps, but we will explore how to write an app that is compatible with both computers and mobile phones.

Let's create a news app. Let's write a news class first. We'll write the specific details next time. ​

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; } }

3, Source code:

1. Project address

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

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

3. Blog Park: https://www.cnblogs.com/ruige0000/

4. welcome to WeChat official account: Fourier transform, official account number, only for learning communication, background reply, "gift package", get big data learning materials.

13 May 2020, 10:25 | Views: 7082

Add new comment

For adding a comment, please log in
or create account

0 comments