AndroidAutoSize
🔥 A low-cost Android screen adaptation solution (今日头条屏幕适配方案终极版,一个极低成本的 Android 屏幕适配方案).
Top Related Projects
:fire: Android developers should collect the following utils(updating).
提高 Android UI 开发效率的 UI 库
This is a picker view for android , support linkage effect, timepicker and optionspicker.(时间选择器、省市区三级联动)
🔥🔥🔥Banner 2.0 来了!Android广告图片轮播控件,内部基于ViewPager2实现,Indicator和UI都可以自定义。
🔥下拉刷新、上拉加载、二级刷新、淘宝二楼、RefreshLayout、OverScroll,Android智能下拉刷新框架,支持越界回弹、越界拖动,具有极强的扩展性,集成了几十种炫酷的Header和 Footer。
BRVAH:Powerful and flexible RecyclerAdapter
Quick Overview
AndroidAutoSize is a low-cost Android screen adaptation solution that perfectly supports both portrait and landscape orientations. It provides a flexible way to achieve adaptive UI design for various Android devices with different screen sizes and densities.
Pros
- Easy integration with minimal code changes required
- Supports both Activity and Fragment adaptation
- Provides custom conversion between different units (px, dp, sp)
- Offers flexible configuration options for different screens and orientations
Cons
- May require additional tweaking for complex layouts
- Some users report issues with certain device-specific edge cases
- Documentation is primarily in Chinese, which may be challenging for non-Chinese speakers
Code Examples
- Initialize AndroidAutoSize in your Application class:
public class MyApplication extends Application {
@Override
public void onCreate() {
super.onCreate();
AutoSizeConfig.getInstance().setBaseOnWidth(true).setUseDeviceSize(true);
}
}
- Use AutoSize annotation to specify design dimensions:
@AutoSize(autoSizeWidth = 360, autoSizeHeight = 640)
public class MainActivity extends AppCompatActivity {
// Your activity code
}
- Customize AutoSize behavior for specific components:
AutoSize.autoConvertDensityOfGlobal(this);
AutoSize.autoConvertDensityOfCustomAdapt(this, 667, true);
Getting Started
- Add the dependency to your app's build.gradle file:
dependencies {
implementation 'com.github.JessYanCoding:AndroidAutoSize:v1.2.1'
}
- Initialize AndroidAutoSize in your Application class:
public class MyApplication extends Application {
@Override
public void onCreate() {
super.onCreate();
AutoSizeConfig.getInstance().setBaseOnWidth(true).setUseDeviceSize(true);
}
}
- Use the
@AutoSize
annotation on your activities or implement theCustomAdapt
interface for more granular control.
Competitor Comparisons
:fire: Android developers should collect the following utils(updating).
Pros of AndroidUtilCode
- Comprehensive utility library with a wide range of Android-specific functions
- Regular updates and active community support
- Extensive documentation and examples for easy implementation
Cons of AndroidUtilCode
- Larger library size, potentially increasing app size
- May include unnecessary utilities for specific projects
- Steeper learning curve due to the extensive feature set
Code Comparison
AndroidUtilCode:
ConvertUtils.dp2px(10);
TimeUtils.getNowString();
EncryptUtils.encryptMD5ToString("password");
AndroidAutoSize:
AutoSizeConfig.getInstance().setBaseOnWidth(true);
AutoSizeConfig.getInstance().setUseDeviceSize(true);
AutoSizeConfig.getInstance().setExcludeFontScale(true);
AndroidUtilCode offers a broader range of utility functions for various Android development tasks, while AndroidAutoSize focuses specifically on screen adaptation and sizing. AndroidUtilCode provides more general-purpose tools, whereas AndroidAutoSize offers a specialized solution for responsive layouts across different device sizes.
提高 Android UI 开发效率的 UI 库
Pros of QMUI_Android
- Comprehensive UI component library with a wide range of pre-built elements
- Extensive customization options for UI components
- Active development and support from Tencent, a major tech company
Cons of QMUI_Android
- Steeper learning curve due to its extensive feature set
- Potentially larger app size due to the comprehensive library
- May require more setup and configuration compared to AndroidAutoSize
Code Comparison
AndroidAutoSize focuses on screen adaptation:
AutoSizeConfig.getInstance()
.setBaseOnWidth(false)
.setUseDeviceSize(true)
.setAutoAdaptStrategy(new AutoAdaptStrategy() { ... });
QMUI_Android offers a variety of UI components:
QMUIDialog.MessageDialogBuilder builder = new QMUIDialog.MessageDialogBuilder(context)
.setTitle("Title")
.setMessage("Message")
.addAction("OK", (dialog, index) -> dialog.dismiss());
builder.create().show();
While AndroidAutoSize specializes in screen adaptation, QMUI_Android provides a comprehensive UI toolkit. AndroidAutoSize is more focused and lightweight, while QMUI_Android offers a broader range of features but may require more resources and setup time.
This is a picker view for android , support linkage effect, timepicker and optionspicker.(时间选择器、省市区三级联动)
Pros of Android-PickerView
- Specialized for creating customizable picker views, offering a wide range of options for date, time, and custom data selection
- Provides a user-friendly interface for selecting values from a scrollable wheel
- Supports both bottom and center dialog modes for flexible integration into various app designs
Cons of Android-PickerView
- Limited to picker view functionality, lacking the comprehensive screen adaptation features of AndroidAutoSize
- May require additional configuration and customization for complex use cases
- Less suitable for projects that don't specifically need picker views
Code Comparison
AndroidAutoSize:
AutoSizeConfig.getInstance()
.setBaseOnWidth(true)
.setUseDeviceSize(false)
.setDesignWidthInDp(360);
Android-PickerView:
TimePickerView pvTime = new TimePickerBuilder(this, new OnTimeSelectListener() {
@Override
public void onTimeSelect(Date date, View v) {
// Handle time selection
}
}).build();
pvTime.show();
While AndroidAutoSize focuses on screen adaptation and responsive layouts, Android-PickerView specializes in creating customizable picker views for various data types. The choice between these libraries depends on the specific requirements of your Android project.
🔥🔥🔥Banner 2.0 来了!Android广告图片轮播控件,内部基于ViewPager2实现,Indicator和UI都可以自定义。
Pros of banner
- Focused on creating image sliders and banners for Android apps
- Offers a wide range of customization options for banner appearance and behavior
- Includes built-in support for various animation effects and transitions
Cons of banner
- Limited to banner/slider functionality, not a comprehensive UI scaling solution
- May require additional work to integrate with other UI components
- Potentially higher learning curve for complex banner configurations
Code Comparison
banner:
Banner banner = findViewById(R.id.banner);
banner.setImages(imageList)
.setBannerStyle(BannerConfig.CIRCLE_INDICATOR_TITLE)
.setIndicatorGravity(BannerConfig.CENTER)
.start();
AndroidAutoSize:
AutoSizeConfig.getInstance().setCustomFragment(true);
AutoSize.autoConvertDensity(this, 360, true);
While banner focuses on creating image sliders with various customization options, AndroidAutoSize provides a solution for adapting UI elements to different screen sizes. The code snippets demonstrate the different purposes: banner initializes and configures a banner component, while AndroidAutoSize sets up global screen adaptation settings. Choose banner for specific banner/slider needs, and AndroidAutoSize for comprehensive UI scaling across different devices.
🔥下拉刷新、上拉加载、二级刷新、淘宝二楼、RefreshLayout、OverScroll,Android智能下拉刷新框架,支持越界回弹、越界拖动,具有极强的扩展性,集成了几十种炫酷的Header和 Footer。
Pros of SmartRefreshLayout
- Offers a wide range of customizable refresh animations and header styles
- Supports multiple nested scrolling views and custom refresh layouts
- Provides built-in support for various loading states and automatic loading more functionality
Cons of SmartRefreshLayout
- Focused solely on refresh and loading functionality, not a comprehensive UI scaling solution
- May require more setup and configuration for complex layouts
- Potential performance overhead for simpler use cases where full feature set is not needed
Code Comparison
AndroidAutoSize:
AutoSizeConfig.getInstance()
.setBaseOnWidth(true)
.setUseDeviceSize(false)
.setDesignWidthInDp(360)
.setDesignHeightInDp(640);
SmartRefreshLayout:
<com.scwang.smart.refresh.layout.SmartRefreshLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
<com.scwang.smart.refresh.header.ClassicsHeader
android:layout_width="match_parent"
android:layout_height="wrap_content"/>
<androidx.recyclerview.widget.RecyclerView
android:layout_width="match_parent"
android:layout_height="match_parent"/>
</com.scwang.smart.refresh.layout.SmartRefreshLayout>
While AndroidAutoSize focuses on automatic UI scaling across different screen sizes, SmartRefreshLayout specializes in providing advanced refresh and loading functionalities for scrollable views. The choice between these libraries depends on the specific requirements of your Android application.
BRVAH:Powerful and flexible RecyclerAdapter
Pros of BaseRecyclerViewAdapterHelper
- More comprehensive and feature-rich, offering a wide range of functionalities for RecyclerView adapters
- Provides built-in support for common RecyclerView operations like item animations, drag-and-drop, and swipe-to-delete
- Actively maintained with frequent updates and a large community of contributors
Cons of BaseRecyclerViewAdapterHelper
- Steeper learning curve due to its extensive feature set
- May introduce unnecessary complexity for simpler RecyclerView implementations
- Larger library size compared to AndroidAutoSize
Code Comparison
AndroidAutoSize:
AutoSizeConfig.getInstance()
.setBaseOnWidth(false)
.setUseDeviceSize(true)
.setAutoAdaptStrategy(new AutoAdaptStrategy() { ... });
BaseRecyclerViewAdapterHelper:
public class MyAdapter extends BaseQuickAdapter<MyItem, BaseViewHolder> {
public MyAdapter(List<MyItem> data) {
super(R.layout.item_layout, data);
}
@Override
protected void convert(BaseViewHolder helper, MyItem item) {
helper.setText(R.id.title, item.getTitle());
}
}
While AndroidAutoSize focuses on screen adaptation and sizing, BaseRecyclerViewAdapterHelper provides a more robust solution for RecyclerView implementations. The choice between the two depends on the specific needs of your project, with AndroidAutoSize being more suitable for screen adaptation tasks and BaseRecyclerViewAdapterHelper excelling in RecyclerView-related functionalities.
Convert designs to code with AI
Introducing Visual Copilot: A new AI model to turn Figma designs to high quality code using your components.
Try Visual CopilotREADME
A low-cost Android screen adaptation solution (ä»æ¥å¤´æ¡å±å¹éé æ¹æ¡ç»æçï¼ä¸ä¸ªæä½ææ¬ç Android å±å¹éé æ¹æ¡).
Overview
Pixel 2 XL | 1440 x 2880 | 560dpi:
Pixel XL | 1440 x 2560 | 560dpi:
Nexus 5X | 1080 x 1920 | 420dpi:
Nexus 4 | 768 x 1280 | 320dpi:
Nexus S | 480 x 800 | 240dpi:
Notice
Download
Jcenter ( â ï¸ DEPRECATION WARNING: the JCenter repository will keep serving packages until February 1st, 2022):
implementation 'me.jessyan:autosize:1.2.1'
JitPack:
Step 1. Add the JitPack repository in your root build.gradle at the end of repositories:
allprojects {
repositories {
...
maven { url "https://jitpack.io" }
}
}
Step 2. Add the dependency
dependencies {
implementation 'com.github.JessYanCoding:AndroidAutoSize:v1.2.1'
}
Usage
Step 1 (just one steps)
- Initialize in AndroidManifest, if you use a subunits, you can write the pixel size, no need to convert the pixel to dp, please see demo-subunits
<manifest>
<application>
<meta-data
android:name="design_width_in_dp"
android:value="360"/>
<meta-data
android:name="design_height_in_dp"
android:value="640"/>
</application>
</manifest>
Preview
-
Real-time preview during layout is an important part of the development phase, in many cases, the default preview device provided by Android Studio does not fully display our design, so we need to create the virtual device ourselves, under the dp, pt, in, mm four units of virtual device creation method
-
If you don't want the status bar and navigation bar to appear in Preview during preview, you can select the panel theme according to the following image, after using this theme, the vertical resolution just fills the entire preview page
-
Virtual device creation method
DP
- If you use dp as a unit in the layout file for layout (AndroidAutoSize supports dp, sp for layout by default), you can find the screen size according to the formula (sqrt(vertical resolution^2 + horizontal resolution^2))/dpi and create an virtual device (write screen size and resolution only)
PT
- If you use pt as a unit in the layout file for layout (requires AutoSizeConfig.getInstance().getUnitsManager().setSupportSubunits(Subunits.PT); to open pt support), you can find the screen size according to the formula (sqrt(vertical resolution^2 + horizontal resolution^2))/72 and create an virtual device (write screen size and resolution only)
IN
- If you use in as a unit in the layout file for layout (requires AutoSizeConfig.getInstance().getUnitsManager().setSupportSubunits(Subunits.IN); to open in support), you can find the screen size according to the formula sqrt(vertical resolution^2 + horizontal resolution^2) and create an virtual device (write screen size and resolution only)
MM
- If you use mm as a unit in the layout file for layout (requires AutoSizeConfig.getInstance().getUnitsManager().setSupportSubunits(Subunits.MM); to open mm support), you can find the screen size according to the formula (sqrt(vertical resolution^2 + horizontal resolution^2))/25.4 and create an virtual device (write screen size and resolution only)
Advance (see demo)
Activity
- Customize the adaptation parameters of the Activity:
public class CustomAdaptActivity extends AppCompatActivity implements CustomAdapt {
@Override
public boolean isBaseOnWidth() {
return false;
}
@Override
public float getSizeInDp() {
return 667;
}
}
- Cancel the adaptation of the Activity:
public class CancelAdaptActivity extends AppCompatActivity implements CancelAdapt {
}
Fragment
- First enable the ability to support Fragment custom parameters
AutoSizeConfig.getInstance().setCustomFragment(true);
- Customize the adaptation parameters of the Fragment:
public class CustomAdaptFragment extends Fragment implements CustomAdapt {
@Override
public boolean isBaseOnWidth() {
return false;
}
@Override
public float getSizeInDp() {
return 667;
}
}
- Cancel the adaptation of the Fragment:
public class CancelAdaptFragment extends Fragment implements CancelAdapt {
}
Subunits (see demo-subunits)
- You can choose one of the three unpopular units of pt, in, mm as the subunits, the subunits is used to avoid the adverse effects caused by modifying DisplayMetrics#density, after using the subunits, you can write the pixel size on the design, you don't need to convert it to dp
AutoSizeConfig.getInstance().getUnitsManager()
.setSupportDP(false)
.setSupportSP(false)
.setSupportSubunits(Subunits.MM);
About Me
- Email: jess.yan.effort@gmail.com
- Home: http://jessyan.me
- æé: https://juejin.im/user/57a9dbd9165abd0061714613
- ç®ä¹¦: https://www.jianshu.com/u/1d0c0bc634db
License
Copyright 2018, jessyan
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
Top Related Projects
:fire: Android developers should collect the following utils(updating).
提高 Android UI 开发效率的 UI 库
This is a picker view for android , support linkage effect, timepicker and optionspicker.(时间选择器、省市区三级联动)
🔥🔥🔥Banner 2.0 来了!Android广告图片轮播控件,内部基于ViewPager2实现,Indicator和UI都可以自定义。
🔥下拉刷新、上拉加载、二级刷新、淘宝二楼、RefreshLayout、OverScroll,Android智能下拉刷新框架,支持越界回弹、越界拖动,具有极强的扩展性,集成了几十种炫 酷的Header和 Footer。
BRVAH:Powerful and flexible RecyclerAdapter
Convert designs to code with AI
Introducing Visual Copilot: A new AI model to turn Figma designs to high quality code using your components.
Try Visual Copilot