All Projects → hjhrq1991 → screenAdaptation

hjhrq1991 / screenAdaptation

Licence: Apache-2.0 License
Android screen UI adaptation

Programming Languages

java
68154 projects - #9 most used programming language

Projects that are alternatives of or similar to screenAdaptation

Autoinch
优雅的iPhone全尺寸/等比例精准适配工具
Stars: ✭ 395 (+1545.83%)
Mutual labels:  adapter, screen
sequelize-adapter
Sequelize adapter for Casbin
Stars: ✭ 51 (+112.5%)
Mutual labels:  adapter
twitter-for-geoevent
ArcGIS GeoEvent Server sample Twitter connectors for sending and receiving tweets.
Stars: ✭ 21 (-12.5%)
Mutual labels:  adapter
IRLSize
A library for determining the actual physical size of pixels on an iOS device.
Stars: ✭ 14 (-41.67%)
Mutual labels:  screen
database
Advanced Database Access Service for Moleculer microservices framework
Stars: ✭ 22 (-8.33%)
Mutual labels:  adapter
jdbc-adapter
JDBC adapter for Casbin
Stars: ✭ 26 (+8.33%)
Mutual labels:  adapter
Swiperoo
An extendable adapter which provides swipe-to-delete feature on your customized row item
Stars: ✭ 38 (+58.33%)
Mutual labels:  adapter
MMM-MagicMover
MagicMirror² module to avoid screen burn-in
Stars: ✭ 21 (-12.5%)
Mutual labels:  screen
AdapterLayout
ViewGroup backed by RecyclerView.Adapter = magic
Stars: ✭ 58 (+141.67%)
Mutual labels:  adapter
recycler-adapter
RecyclerView-driven declarative UIs
Stars: ✭ 124 (+416.67%)
Mutual labels:  adapter
create-adapter
Command line utility to create customized ioBroker adapters
Stars: ✭ 39 (+62.5%)
Mutual labels:  adapter
EasyAdapter
An simplify and practical version for hongyangAndroid [baseAdapter],重构了代码,并适配Kotlin。
Stars: ✭ 18 (-25%)
Mutual labels:  adapter
Atomic-Periodic-Table.Android
Atomic - Periodic Table
Stars: ✭ 33 (+37.5%)
Mutual labels:  adapter
Mosque-Screen
Chat: https://discord.gg/CG7frj2 - Email: [email protected]. We do not provide any support, this is a volunteer-based project therefore we cannot commit to any time to resolve local issues.
Stars: ✭ 54 (+125%)
Mutual labels:  screen
YellowDot
Hide the macOS yellow recording dot in the corner of your screen
Stars: ✭ 21 (-12.5%)
Mutual labels:  screen
hubot-dingtalk
hubot-dingtalk:支持钉钉Outgoing
Stars: ✭ 29 (+20.83%)
Mutual labels:  adapter
keyonic-v2
A Keycloak Mobile Implementation using Angular v4 and Ionic v3
Stars: ✭ 23 (-4.17%)
Mutual labels:  adapter
macos-blank-screensaver
Blank (black) screensaver for MacOS
Stars: ✭ 27 (+12.5%)
Mutual labels:  screen
GhostAdapter
No description or website provided.
Stars: ✭ 15 (-37.5%)
Mutual labels:  adapter
SimpleScreens
Simple Screens is a library of screens and screen components (forms, sections, transitions) to be included, extended, or generally reused in applications based on Moqui Framework and Mantle Business Artifacts.
Stars: ✭ 20 (-16.67%)
Mutual labels:  screen

ScreenAdapter

中文文档

The ScreenAdapter project comes from the developer when the designer makes fun of the lack of a highly reversion design, and the Android screen has a lot of resolution. It always needs to fine-tune or discard the non-mainstream resolution. The ScreenAdapter is born and has experienced multiple project practices, and the adaptation situation has basically achieved the ideal situation.

The ScreenAdapter has the following features:

  • Simple and convenient
    • access is simple, rarely accessed
    • the code and layout are converted to the global entry
  • Better layout
    • dp can be replaced by pt/in/mm
    • you can use the design draft to mark the dimensions directly
    • no layout nesting can be implemented
  • performance better
    • no need to rely on third-party libraries such as AutoLayout

How to use the ScreenAdapter?

If you feel that the ScreenAdapter is helpful to you, your star and issues will be the biggest support for me.^_^

Sample

When you look at this design, how do you restore it at all resolutions? design

effect

Adaptation case:

Describe Huawei Honor8 Meizu MX3 Meizu MX2
resolution 1920*1080 1800*1080 1280*800
aspect ratio 16:9 15:9 16:10
effect honor8 mx3 mx2

Download

Download

compile 'com.hjhrq991.screenadapter:ScreenAdapter:1.0.5'

Use

No Application

You can use ScreenAdapterApplication in AndroidManifest

   <application
          android:name="com.hjhrq991.screenadapter.ScreenAdapterApplication">
           
      </application>

Has custom Application

If your custom Application extends Application, modify it to extend ScreenAdapterApplication

   public class MyApplication extends ScreenAdapterApplication {
   
   }

If your custom Application extends other Application, it can be done by ScreenAdaperHelper. DESIGN_WIDTH is the width of the design draft (if your design draft is not uniform, please find your designer), and the value of DESIGN_WIDTH is recommended to use the result of px, which is px/ 2. The specific code is as follows:

    private float DESIGN_WIDTH = 375f;
    private ScreenAdaperHelper mHelper;

    @Override
    public void onCreate() {
        super.onCreate();
        //init helper with the width for design drawing
        mHelper = new ScreenAdaperHelper.Builder()
                .setApplication(this)
                .setDesign_with(DESIGN_WIDTH)
                .setUnit(TypedValue.COMPLEX_UNIT_PT)
                .setEnableDp(true)
                .setEnableOtherResources(true)
                .build();
    }

    @Override
    public void onConfigurationChanged(Configuration newConfig) {
        super.onConfigurationChanged(newConfig);
        mHelper.onConfigurationChanged();
    }

    @Override
    public Resources getResources() {
        Resources res = super.getResources();
        //Will call before init
        if (mHelper != null)
            mHelper.getResources(res);
        return res;
    }

Adaptation

Layout adaptation

Given the runtime the scheme is valid, so suggest writing layout file is preferred to use dp as a unit, after finished the layout using pt/in/mm global replace dp. Of course, if take the trouble of can in the Android studiod preview function can be used when the simulator equipment preview, fill out the design draft size, good screen size conversion to preview. It is also recommended to use the FrameLayout or linear layout to minimize the use of RelativeLayout, which can reduce the hierarchy.

<?xml version="1.0" encoding="utf-8"?>
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="375pt"
    android:layout_height="240pt"
    android:background="@color/white"
    android:layout_marginBottom="15pt"
    android:orientation="vertical">

    <FrameLayout
        android:id="@+id/layout_left"
        android:layout_width="160pt"
        android:layout_height="240pt">

        <View
            android:layout_width="150pt"
            android:layout_height="150pt"
            android:layout_gravity="bottom|center_horizontal"
            android:layout_margin="5pt"
            android:background="@color/gray" />

        <View
            android:layout_width="match_parent"
            android:layout_height="14pt"
            android:layout_marginLeft="15pt"
            android:layout_marginRight="15pt"
            android:layout_marginTop="10pt"
            android:background="@color/gray" />

        <View
            android:layout_width="90pt"
            android:layout_height="10pt"
            android:layout_marginLeft="15pt"
            android:layout_marginTop="32pt"
            android:background="@color/gray"
            android:gravity="center_vertical" />

        <View
            android:layout_width="60pt"
            android:layout_height="26pt"
            android:layout_marginLeft="15pt"
            android:layout_marginRight="15pt"
            android:layout_marginTop="45pt"
            android:background="@color/gray" />
    </FrameLayout>

    <android.support.v7.widget.RecyclerView
        android:id="@+id/gridview"
        android:layout_width="215pt"
        android:layout_height="240pt"
        android:layout_gravity="right"
        android:listSelector="@color/white" />

    <View
        android:layout_width="0.5pt"
        android:layout_height="match_parent"
        android:layout_marginLeft="160pt"
        android:background="@color/ececec" />

    <View
        android:layout_width="0.5pt"
        android:layout_height="match_parent"
        android:layout_gravity="right"
        android:layout_marginRight="107.5pt"
        android:background="@color/ececec" />

    <View
        android:layout_width="215pt"
        android:layout_height="0.5pt"
        android:layout_gravity="center_vertical|right"
        android:background="@color/ececec" />
        
</FrameLayout>
<?xml version="1.0" encoding="utf-8"?>
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="120pt"
    android:paddingBottom="2pt"
    android:paddingLeft="15pt"
    android:paddingRight="15pt"
    android:paddingTop="10pt">

    <View
        android:layout_width="match_parent"
        android:layout_height="14pt"
        android:background="@color/gray" />

    <View
        android:layout_width="match_parent"
        android:layout_height="10pt"
        android:layout_marginRight="15pt"
        android:layout_marginTop="16pt"
        android:background="@color/gray" />

    <View
        android:layout_width="77pt"
        android:layout_height="77pt"
        android:layout_gravity="bottom|center_horizontal"
        android:background="@color/gray" />
</FrameLayout>

Code adaptation

If you need to write code to convert px, you can call the ScreenAdaperHelper API method:

ScreenAdaperHelper.ptTopx(mContext, 210);

Of course, it's ok to call your original method, which is already global.

Adaptation situation

All devices can be highly restored to the design draft effect. The layout USES pt/in/mm to replace dp and sp, but the dp and sp are retained with high frequency of use. The horizontal vertical screen switching will be converted to the current screen width, such as your layout non-list or Scrollview, which suggests that the horizontal vertical screen should be adapted with different layout.

  • v1.0.0
    • Most of the models have been adapted to most models such as huawei, meizu, vivo, oppo, samsung, one plus, zte, coolpad, hammer, Letv, etc
    • Solve the problem that DisplayMetrics is reset in some cases
  • v1.0.1
    • Optimize the access method for visual area width
  • v1.0.2
    • Fix the problem of the failure of the adaptation programme under the xiaomi android 5.1.1
    • Add code to convert px tools
  • v1.0.3
    • Optimize the ScreenAdapterHelper initialization method
    • Increase dp/dip conversion
    • Add the enable switch for MIUI/XPOSE
  • v1.0.4
    • Solve the recursive call problem for xiaomi 4C、Note PRO、4S(Android 7.0)

Current unresolved issues:For example, huawei mobile phone, in the case of horizontal screen, hide/show the navigation bar does not have a good way to monitor, and it will not trigger page refresh. Forcing the UI to refresh the UI is bound to waste performance. Of course, if you need to deal with this problem, you can redraw the UI by yourself in the Activity listening to the changes in android. Id. R.content width. If you have a good solution to this problem, please give me feedback! Thank you!

Other

If you have any questions, please give me feedback on issues
Or contact me in other ways:
Gmail:[email protected]
QQ:444563258


License

Apache 2.0

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].