- Mastering Android Studio 3
- Kyle Mew
- 273字
- 2021-07-02 18:42:36
Controlling position with bias
Bias can be best understood here as a percentage value, but rather than position the view according to its center or a corner, it is the percentage of space either side of it. So if the bias towards the top is 33%, then the margin below will be twice the size of the one below it.
Setting bias is even easier than understanding it, as once a constraint is set on any opposing sides of a view, an associated slider will appear in the Properties graphic Properties editor:

A quick glance at the generated code shows the format for this attribute as follows:
app:layout_constraintHorizontal_bias="0.33"
The value of using bias to position screen elements lies partly in the simplistic approach, but its true value comes when it comes to developing for multiple screens. There are so many models available and they all seem to have slightly different proportions. This can make design layouts that look fantastic on all of them, very time consuming and even shapes as similar as 720 x 1280 and 768 x 1280 can produce undesirable results when tested with the same layout. The use of the bias attribute goes a long way to solving these issues, and we shall see more of this later when we take a look at layout previews and the percent library.
As if all this didn't make designing a layout easy enough, constraint layouts have two other extremely handy functions that almost automate UI design: auto-connect and inference.
- Java EE 6 企業級應用開發教程
- Cocos2d-x游戲開發:手把手教你Lua語言的編程方法
- Learning C++ Functional Programming
- 我的第一本算法書
- INSTANT CakePHP Starter
- MATLAB定量決策五大類問題
- Java程序設計
- Node Cookbook(Second Edition)
- 算法設計與分析:基于C++編程語言的描述
- 視窗軟件設計和開發自動化:可視化D++語言
- C語言程序設計
- 透視C#核心技術:系統架構及移動端開發
- 從零開始學UI設計·基礎篇
- HTML5 Game Development by Example:Beginner's Guide(Second Edition)
- Swift Essentials(Second Edition)