From e8addd404faf6085b8a5604c62220790daaf2ac8 Mon Sep 17 00:00:00 2001 From: Hossain Khan Date: Fri, 5 Apr 2019 16:24:15 -0400 Subject: [PATCH] [ADDED] [#53] Percent Dimension example. Fixes #53 --- README.md | 6 +- .../android/demo/data/LayoutDataStore.kt | 9 ++- .../drawable/thumb_dimension_percentage.xml | 54 ++++++++++++++++ .../res/layout/preview_dimension_percent.xml | 61 +++++++++++++++++++ resources/vector/ic_dimension_percentage.svg | 3 + 5 files changed, 129 insertions(+), 4 deletions(-) create mode 100644 app/src/main/res/drawable/thumb_dimension_percentage.xml create mode 100644 app/src/main/res/layout/preview_dimension_percent.xml create mode 100644 resources/vector/ic_dimension_percentage.svg diff --git a/README.md b/README.md index 3297480..fe2d7e8 100644 --- a/README.md +++ b/README.md @@ -34,14 +34,14 @@ See https://github.com/googlesamples/android-ConstraintLayoutExamples - [x] Visibility behavior - [ ] Dimension constraints * [x] Ratio - * [ ] Percent dimension + * [x] Percent dimension * [ ] Min and Max * [ ] `MATCH_CONSTRAINT` dimensions _(Added in 1.1)_ * [ ] `WRAP_CONTENT` : enforcing constraints _(Added in 1.1)_ * [ ] Widgets dimension constraints - [ ] Chains * [x] Chain Style - * [ ] Weighted chains + * [x] Weighted chains * [ ] Margins and chains _(Added in 1.1)_ - [ ] Virtual Helpers objects * [ ] Guideline @@ -51,7 +51,7 @@ See https://github.com/googlesamples/android-ConstraintLayoutExamples ## Objective These are the **my** objectives for this demo application. -* To explore all the features of constrainst layout +* To explore all the features of constraint layout * Learn and use material design component in the sample app * Learn and use the new architecture components in the sample app * Learn and use proper architecture for the app - likely MVVM diff --git a/app/src/main/java/com/hossainkhan/android/demo/data/LayoutDataStore.kt b/app/src/main/java/com/hossainkhan/android/demo/data/LayoutDataStore.kt index de1d5dc..c47c109 100644 --- a/app/src/main/java/com/hossainkhan/android/demo/data/LayoutDataStore.kt +++ b/app/src/main/java/com/hossainkhan/android/demo/data/LayoutDataStore.kt @@ -110,7 +110,14 @@ class LayoutDataStore @Inject constructor( "\n\n" + "The ratio can be expressed either as:\n" + "\n * a float value, representing a ratio between width and height" + - "\n * a ratio in the form \"width:height\", for example: `layout_constraintDimensionRatio=\"16:9\"`") + "\n * a ratio in the form \"width:height\", for example: `layout_constraintDimensionRatio=\"16:9\"`"), + LayoutInformation( + layoutResourceId = R.layout.preview_dimension_percent, + thumbnailResourceId = R.drawable.thumb_dimension_percentage, + title = "Dimension: Percent dimension", + description = "To use percent, you need to set the following:\n\n" + + "* The dimension should be set to MATCH_CONSTRAINT (0dp)\n" + + "* Then set the `layout_constraintWidth_percent` or `layout_constraintHeight_percent` attributes to a value between 0.0 and 1.0") /* Next item template (easy to copy and paste) LayoutInformation( diff --git a/app/src/main/res/drawable/thumb_dimension_percentage.xml b/app/src/main/res/drawable/thumb_dimension_percentage.xml new file mode 100644 index 0000000..8511f4d --- /dev/null +++ b/app/src/main/res/drawable/thumb_dimension_percentage.xml @@ -0,0 +1,54 @@ + + + + + + + + + + + + + + + + + + + + + + diff --git a/app/src/main/res/layout/preview_dimension_percent.xml b/app/src/main/res/layout/preview_dimension_percent.xml new file mode 100644 index 0000000..0e2d3c5 --- /dev/null +++ b/app/src/main/res/layout/preview_dimension_percent.xml @@ -0,0 +1,61 @@ + + + + + + + + + + + + + + \ No newline at end of file diff --git a/resources/vector/ic_dimension_percentage.svg b/resources/vector/ic_dimension_percentage.svg new file mode 100644 index 0000000..bfac1a8 --- /dev/null +++ b/resources/vector/ic_dimension_percentage.svg @@ -0,0 +1,3 @@ + + + \ No newline at end of file