In this tutorial I will guide you on How to import Vector Assets and Drawables in your Android application.
I will also cover how to give support for devices which do not support vector assets using AppCompat library.
Importing Vector Asset using Android Studio
In case of Vector Assets You do not directly copy paste your icons and images in drawable folder.
There is tool in Android Studio for importing Vector Assest or Scalable Vector Graphics (SVG).
Go to File => New => and select Vector Asset.
Importing Vector Assets (SVG) Android Studio
You can also enable RTL (Right to Left) support. When your
application will be running in RTL mode, your SVG icon will be flipped
automatically.
After this step SVG file which you imported above will be converted into XML file.
Vector Drawable XML Preview
At this step we are ready to use above icon in our application but there is a lot more to do.
Backward Compatibility for SVG
Vector Drawables or Scalable Vector Graphics (SVG) were introduced in Android 5.0 (API Level 21).
If your application support devices lower than API Level 21 still you
can use Vector Drawables on devices lower than API Level 21 using
AppCompat Library.
Because AppCompat Library suport Android 2.1 (API Level 7+).
For Fragment Reload // Reload current fragment Fragment frg = null ; frg = getSupportFragmentManager (). findFragmentByTag ( "Your_Fragment_TAG" ); final FragmentTransaction ft = getSupportFragmentManager (). beginTransaction (); ft . detach ( frg ); ft . attach ( frg ); ft . commit (); Your_Fragment_TAG is the name you gave your fragment when you created it This code is for support library. If you're not supporting older devices, just use getFragmentManager instead of getSupportFragmentManager For Activity Reload Intent i = new Intent(MainActivity.this, MainActivity.class); finish(); overridePendingTransition(0, 0); startActivity(i); overridePendingTransition(0, 0); In the above code, we have used overridePendingTransition(), it is used to remove activity create animation while re-creating activity.
ConstraintLayout allows you to create large and complex layouts with a flat view hierarchy (no nested view groups). It's similar to RelativeLayout in that all views are laid out according to relationships between sibling views and the parent layout, but it's more flexible than RelativeLayout and easier to use with Android Studio's Layout Editor. All the power of ConstraintLayout is available directly from the Layout Editor's visual tools, because the layout API and the Layout Editor were specially built for each other. So you can build your layout with ConstraintLayout entirely by drag-and-dropping instead of editing the XML. ConstraintLayout is available in an API library that's compatible with Android 2.3 (API level 9) and higher. This page provides a guide to building a layout with ConstraintLayout in Android Studio 3.0 or higher. If you'd like more information about the Layout Editor itself, see the Android Studio guide to Build a UI with L...
LinearLayout is a view group that aligns all children in a single direction, vertically or horizontally. You can specify the layout direction with the android:orientation attribute. Note: For better performance and tooling support, you should instead build your layout with ConstraintLayout . All children of a LinearLayout are stacked one after the other, so a vertical list will only have one child per row, no matter how wide they are, and a horizontal list will only be one row high (the height of the tallest child, plus padding). A LinearLayout respects margin s between children and the gravity (right, center, or left alignment) of each child. Layout Weight LinearLayout also supports assigning a weight to individual children with the android:layout_weight attribute. This attribute assigns an "importance" value to a view in terms of how much space it should occupy on the screen. A larger weight value allows it to expand to fill any remaining space in the pa...
Comments
Post a Comment