Skip to content
This repository was archived by the owner on Aug 22, 2024. It is now read-only.

Commit fdbd794

Browse files
committed
[ADDED] [#27] Added layout with horizontal and vertical bias.
1 parent 0687da0 commit fdbd794

File tree

5 files changed

+103
-7
lines changed

5 files changed

+103
-7
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ A demo application for Android `ConstraintLayout` with various usage with sample
2121
- [ ] Margins
2222
- [x] Centering positioning and bias
2323
- [x] Circular positioning _(Added in 1.1)_
24-
- [ ] Visibility behavior
24+
- [x] Visibility behavior
2525
- [ ] Dimension constraints
2626
* [ ] Ratio
2727
* [ ] Percent dimension

app/src/main/java/com/hossainkhan/android/demo/browse/MainActivity.kt

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -62,17 +62,15 @@ class MainActivity : AppCompatActivity() {
6262
}
6363
}
6464

65-
fun onLayoutItemSelected(layoutResId: Int) {
65+
private fun onLayoutItemSelected(layoutResId: Int) {
6666
Timber.i("Selected layout id: %s", layoutResId)
6767

6868
when (layoutResId) {
6969
R.layout.preview_visibility_gone -> {
70-
startActivity(LayoutVisibilityGoneActivity
71-
.createStartIntent(this))
70+
startActivity(LayoutVisibilityGoneActivity.createStartIntent(this))
7271
}
7372
else -> {
74-
startActivity(LayoutPreviewBaseActivity
75-
.createStartIntent(this, layoutResId))
73+
startActivity(LayoutPreviewBaseActivity.createStartIntent(this, layoutResId))
7674
}
7775
}
7876

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<!--
3+
~ Copyright (c) 2018 Hossain Khan
4+
~
5+
~ Licensed under the Apache License, Version 2.0 (the "License");
6+
~ you may not use this file except in compliance with the License.
7+
~ You may obtain a copy of the License at
8+
~
9+
~ http://www.apache.org/licenses/LICENSE-2.0
10+
~
11+
~ Unless required by applicable law or agreed to in writing, software
12+
~ distributed under the License is distributed on an "AS IS" BASIS,
13+
~ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
~ See the License for the specific language governing permissions and
15+
~ limitations under the License.
16+
-->
17+
18+
<merge xmlns:tools="http://schemas.android.com/tools"
19+
xmlns:app="http://schemas.android.com/apk/res-auto"
20+
xmlns:android="http://schemas.android.com/apk/res/android"
21+
tools:showIn="@layout/preview_positioning_bias">
22+
23+
24+
<TextView
25+
android:layout_width="wrap_content"
26+
android:layout_height="wrap_content"
27+
android:layout_marginStart="8dp"
28+
android:text="Horizontal Bias = 20%\n(Towards Left)"
29+
app:layout_constraintBottom_toBottomOf="@+id/view_positioning_bias_20_percent"
30+
app:layout_constraintStart_toEndOf="@+id/view_positioning_bias_20_percent"
31+
app:layout_constraintTop_toTopOf="@+id/view_positioning_bias_20_percent" />
32+
33+
<TextView
34+
android:layout_width="wrap_content"
35+
android:layout_height="wrap_content"
36+
android:layout_marginTop="8dp"
37+
android:text="Vertical Bias = 85% (Towards Bottom)"
38+
app:layout_constraintEnd_toEndOf="@+id/view_positioning_bias_85_percent"
39+
app:layout_constraintStart_toStartOf="@+id/view_positioning_bias_85_percent"
40+
app:layout_constraintTop_toBottomOf="@+id/view_positioning_bias_85_percent" />
41+
</merge>
Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
<?xml version="1.0" encoding="utf-8"?><!--
2+
~ Copyright (c) 2018 Hossain Khan
3+
~
4+
~ Licensed under the Apache License, Version 2.0 (the "License");
5+
~ you may not use this file except in compliance with the License.
6+
~ You may obtain a copy of the License at
7+
~
8+
~ http://www.apache.org/licenses/LICENSE-2.0
9+
~
10+
~ Unless required by applicable law or agreed to in writing, software
11+
~ distributed under the License is distributed on an "AS IS" BASIS,
12+
~ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
~ See the License for the specific language governing permissions and
14+
~ limitations under the License.
15+
-->
16+
17+
<android.support.constraint.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
18+
xmlns:app="http://schemas.android.com/apk/res-auto"
19+
xmlns:tools="http://schemas.android.com/tools"
20+
android:layout_width="match_parent"
21+
android:layout_height="match_parent"
22+
android:foreground="@drawable/ic_grid_overlay"
23+
android:foregroundTint="@color/grid_tint"
24+
tools:context=".layoutpreview.LayoutPreviewBaseActivity">
25+
26+
<!--
27+
1st view that is horizontally biased towards the bottom using 85% bias
28+
-->
29+
<View
30+
android:id="@+id/view_positioning_bias_20_percent"
31+
style="@style/MediumBox"
32+
android:layout_marginTop="50dp"
33+
app:layout_constraintEnd_toEndOf="parent"
34+
app:layout_constraintHorizontal_bias="0.20"
35+
app:layout_constraintStart_toStartOf="parent"
36+
app:layout_constraintTop_toTopOf="parent" />
37+
38+
39+
<!--
40+
2nd view that is vertically biased towards the bottom using 85% bias
41+
-->
42+
<View
43+
android:id="@+id/view_positioning_bias_85_percent"
44+
style="@style/MediumBox.Purple"
45+
app:layout_constraintBottom_toBottomOf="parent"
46+
app:layout_constraintEnd_toEndOf="parent"
47+
app:layout_constraintStart_toStartOf="parent"
48+
app:layout_constraintTop_toTopOf="parent"
49+
app:layout_constraintVertical_bias="0.85" />
50+
51+
<!--
52+
Additional text views to explain the views - Ignore
53+
-->
54+
<include layout="@layout/include_layout_positioning_bias" />
55+
56+
57+
</android.support.constraint.ConstraintLayout>

app/src/main/res/values/styles.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
<style name="MediumBox">
1212
<item name="android:layout_width">@dimen/box_size_medium</item>
1313
<item name="android:layout_height">@dimen/box_size_medium</item>
14-
<item name="android:background">@color/md_red_700</item>
14+
<item name="android:background">@color/md_amber_700</item>
1515
</style>
1616

1717
<style name="MediumBox.Purple">

0 commit comments

Comments
 (0)