AndroidAutoLayout


Source link: https://github.com/hongyangAndroid/AndroidAutoLayout

AndroidAutoLayout

[DEPRECATED]Android???????????????????????????

??????????????????????????????????????????????????????

???? ? ????? ????

???

??????????????????????

so,?????

??????????????????????????px???px:???px???Google??????px????????????

ok????????????????????????

???768 * 1280 ; ???1080 * 1920

?????????????????????????????????

  • ??????????????????????dp
  • ??????????????dimens
  • ??????????????????????????
  • ??????UI MM??????dp?

???????????????px??????????

????????????Item????????????????????FrameLayout????View????marginLeft,marginTop????????????????

??

  • Android Studio

? autolayout??

dependencies {

  compile project(':autolayout') 
}

?????

dependencies {

  compile 'com.zhy:autolayout:1.4.5' 
}
 
  • Eclipse

????As???????????????????????

??

????

??????AndroidManifest????? ???????

<meta-data android:name="design_width" android:value="768"> </meta-data> <meta-data android:name="design_height" android:value="1280"> </meta-data>
  

????

???Activity??? AutoLayoutActivity.

???????????????????????????????sample?

????

???????? AutoLayoutActivity?????????????

  • LinearLayout -> AutoLinearLayout
  • RelativeLayout -> AutoRelativeLayout
  • FrameLayout -> AutoFrameLayout

??????????

??????

  • layout_width
  • layout_height
  • layout_margin(left,top,right,bottom)
  • pading(left,top,right,bottom)
  • textSize
  • maxWidth, minWidth, maxHeight, minHeight

??

??????????????????????????????????????????????????????

???Application?onCreate???????:

public class UseDeviceSizeApplication extends Application {

  @Override
  public void onCreate()
  {

super.onCreate();

AutoLayoutConifg.getInstance().useDeviceSize();

  
}
 
}
 

??

???????????????????????????????????????????????????????????????????PreView???????

????????????????? 768 * 1280

?????PreView??????????????????

???????? ?????????

???????

  1. ??UI??????????????????????????????????????
  2. ???PreView????????????????????????????????????

??

?????????FrameLayout?LinearLayout?RelativeLayout?????? CardView?????????????"px"??????????????????????????? issue#21?

package com.zhy.sample.view;  import android.content.Context; import android.support.v7.widget.CardView; import android.util.AttributeSet;  import com.zhy.autolayout.AutoFrameLayout; import com.zhy.autolayout.utils.AutoLayoutHelper;  /**  * Created by zhy on 15/12/8.  */ public class AutoCardView extends CardView {

  private final AutoLayoutHelper mHelper = new AutoLayoutHelper(this);

public AutoCardView(Context context)
  {

super(context);

  
}

public AutoCardView(Context context, AttributeSet attrs)
  {

super(context, attrs);

  
}

public AutoCardView(Context context, AttributeSet attrs, int defStyleAttr)
  {

super(context, attrs, defStyleAttr);

  
}

@Override
  public AutoFrameLayout.LayoutParams generateLayoutParams(AttributeSet attrs)
  {

return new AutoFrameLayout.LayoutParams(getContext(), attrs);

  
}

@Override
  protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec)
  {

if (!isInEditMode())

{

 mHelper.adjustChildren();

}

super.onMeasure(widthMeasureSpec, heightMeasureSpec);

  
}

}
 

????

ListView?RecyclerView??Item???

sample???ListView?RecyclerView???????sample

  • ??ListView

??ListView?????item???????“px”??????????????AutoXXXLayout???ListView???????????????????

@Override public View getView(int position, View convertView, ViewGroup parent) {

  ViewHolder holder = null;
  if (convertView == null)
  {

holder = new ViewHolder();

convertView = LayoutInflater.from(mContext).inflate(R.layout.list_item, parent, false);

convertView.setTag(holder);

//??listview????????????item?????

AutoUtils.autoSize(convertView);

  
}
 else
  {

holder = (ViewHolder) convertView.getTag();

  
}

return convertView; 
}

?? AutoUtils.autoSize(convertView); ??????????demo????????

  • ??RecyclerView
public ViewHolder(View itemView) {

 super(itemView);

 AutoUtils.autoSize(itemView);
 
}
  //... @Override public ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {

View convertView = LayoutInflater.from(mContext).inflate(R.layout.recyclerview_item, parent, false);

return new ViewHolder(convertView);
 
}
 

????? LayoutInflater.from(mContext).inflate??????????

??????????????

?????????????????1px??????????????????????????????

app:layout_auto_basewidth="height"???height????????????

app:layout_auto_baseheight="width"???width????????????

???????????????

app:layout_auto_basewidth="height|padding"

?|?????gravity????????

  • width,height
  • margin,marginLeft,marginTop,marginRight,marginBottom
  • padding,paddingLeft,paddingTop,paddingRight,paddingBottom
  • textSize.

TextView?????

??????????????????????textSize="20px"????TextView??????????20px?????????????????????????????????text???margin?????????????????????????????????marginBottom?

????

###(1)????? org/gradle/api/publication/maven/internal/DefaultMavenFactory

????????? compile 'com.zhy:autolayout:x.x.x'?????????????module??????issue #74

###(2)RadioGroup,Toolbar??????View??????

????????????????????????????????????????????? ?? autolayout-widget, ?????????????????????????????????????????????PR?????????????? autolayout-widget??????ps:??????copy?????????? autolayout-widget???????????????? ????????

###(3)java.lang.IllegalStateException: You need to use a Theme.AppCompat theme (or descendant) with this activity.

?????????AutoLayoutActivity????AppCompatActivity????????? Theme.AppCompat?theme?

?????????FragmentActivity????????AppCompatActivity? ??????????? MyAutoLayoutActivity extends ??????Activity????? MyAutoLayoutActivity extends FragmentActivity???????AutoLayoutActivity???? ??????????????? MyAutoLayoutActivity????

ps?????????SDK???? AppCompatActivity.

????

?????

?????

Resources

A fancy CircularProgressView.

Sometimes when working with REST APIs in Android apps there is a need to return some mock data. Maybe for demo purposes, or real endpoint is just not ready yet. Endpoint2mock aims to help with that by integrating with Retrofit and allowing you to easily redirect some (but not all!) of your requests to your mock server.

A light weight library for exporting and importing sqlite database in android.

Resizer is a lightweight and easy-to-use Android library for image scaling. It allows you to resize an image file to a smaller or bigger one while keeping the aspect ratio.

Droid-vizu aims to provide cool visualization effects for any Android audio project. Maintainable modular design allows users to easily swap Renderer class to get corresponding effects.

A customize multiple state layout for Android.

Topics


2D Engines   3D Engines   9-Patch   Action Bars   Activities   ADB   Advertisements   Analytics   Animations   ANR   AOP   API   APK   APT   Architecture   Audio   Autocomplete   Background Processing   Backward Compatibility   Badges   Bar Codes   Benchmarking   Bitmaps   Bluetooth   Blur Effects   Bread Crumbs   BRMS   Browser Extensions   Build Systems   Bundles   Buttons   Caching   Camera   Canvas   Cards   Carousels   Changelog   Checkboxes   Cloud Storages   Color Analysis   Color Pickers   Colors   Comet/Push   Compass Sensors   Conferences   Content Providers   Continuous Integration   Crash Reports   Credit Cards   Credits   CSV   Curl/Flip   Data Binding   Data Generators   Data Structures   Database   Database Browsers   Date &   Debugging   Decompilers   Deep Links   Dependency Injections   Design   Design Patterns   Dex   Dialogs   Distributed Computing   Distribution Platforms   Download Managers   Drawables   Emoji   Emulators   EPUB   Equalizers &   Event Buses   Exception Handling   Face Recognition   Feedback &   File System   File/Directory   Fingerprint   Floating Action   Fonts   Forms   Fragments   FRP   FSM   Functional Programming   Gamepads   Games   Geocaching   Gestures   GIF   Glow Pad   Gradle Plugins   Graphics   Grid Views   Highlighting   HTML   HTTP Mocking   Icons   IDE   IDE Plugins   Image Croppers   Image Loaders   Image Pickers   Image Processing   Image Views   Instrumentation   Intents   Job Schedulers   JSON   Keyboard   Kotlin   Layouts   Library Demos   List View   List Views   Localization   Location   Lock Patterns   Logcat   Logging   Mails   Maps   Markdown   Mathematics   Maven Plugins   MBaaS   Media   Menus   Messaging   MIME   Mobile Web   Native Image   Navigation   NDK   Networking   NFC   NoSQL   Number Pickers   OAuth   Object Mocking   OCR Engines   OpenGL   ORM   Other Pickers   Parallax List   Parcelables   Particle Systems   Password Inputs   PDF   Permissions   Physics Engines   Platforms   Plugin Frameworks   Preferences   Progress Indicators   ProGuard   Properties   Protocol Buffer   Pull To   Purchases   Push/Pull   QR Codes   Quick Return   Radio Buttons   Range Bars   Ratings   Recycler Views   Resources   REST   Ripple Effects   RSS   Screenshots   Scripting   Scroll Views   SDK   Search Inputs   Security   Sensors   Services   Showcase Views   Signatures   Sliding Panels   Snackbars   SOAP   Social Networks   Spannable   Spinners   Splash Screens   SSH   Static Analysis   Status Bars   Styling   SVG   System   Tags   Task Managers   TDD &   Template Engines   Testing   Testing Tools   Text Formatting   Text Views   Text Watchers   Text-to   Toasts   Toolkits For   Tools   Tooltips   Trainings   TV   Twitter   Updaters   USB   User Stories   Utils   Validation   Video   View Adapters   View Pagers   Views   Watch Face   Wearable Data   Wearables   Weather   Web Tools   Web Views   WebRTC   WebSockets   Wheel Widgets   Wi-Fi   Widgets   Windows   Wizards   XML   XMPP   YAML   ZIP Codes