Android “网格布局吐出”;“不一致约束”;调试级日志
我已经使用GridLayout好几个星期了,我注意到当我打电话时Android “网格布局吐出”;“不一致约束”;调试级日志,android,android-layout,grid-layout,Android,Android Layout,Grid Layout,我已经使用GridLayout好几个星期了,我注意到当我打电话时 gridLayout.requestLayout() 它在LogCat中弹出以下调试级别消息: D/android.widget.GridLayout(14048): horizontal constraints: x5 - x0 > 1115, x5 - x4 < 221, x4 - x3 < 221, x3 - x2 < 221, x2 - x1 < 221, x1 - x0 < 221
gridLayout.requestLayout()
它在LogCat中弹出以下调试级别消息:
D/android.widget.GridLayout(14048): horizontal constraints: x5 - x0 > 1115, x5 - x4 < 221, x4 - x3 < 221, x3 - x2 < 221, x2 - x1 < 221, x1 - x0 < 221 are inconsistent; permanently removing: x5 - x4 < 221.
D/android.widget.GridLayout(14048):水平约束:x5-x0>1115,x5-x4<221,x4-x3<221,x3-x2<221,x2-x1<221,x1-x0<221不一致;永久移除:x5-x4<221。
我已经查看了GridLayout的源代码,试图找出“约束不一致”的可能原因,但我还没有弄清楚
事实上,这些信息正在出现——这是我应该关注的事情吗?我认为事情的安排方式没有任何问题。我有一个片段中的GridLayout,作为ViewPager中的页面加载,因此当用户在页面之间滚动时,我在LogCat中多次看到上面的输出。我也有同样的问题,我发现我没有添加XML名称空间。这样更正它:
<android.support.v7.widget.GridLayout
xmlns:grid="http://schemas.android.com/apk/res-auto"
xmlns:android="http://schemas.android.com/apk/res/android">
...
</android.support.v7.widget.GridLayout>
...
然后还更改了compatibility GridLayout与XML命名空间使用的属性前缀:
<ImageButton android:id="@+id/btnSentence"
grid:layout_row="0"
grid:layout_column="0"
...
/>
这有助于。。。希望它也能帮助您。来自
GridLayout
来源:
贝尔曼福特车型-经过修改,将典型运行时间从O(N^2)
减少到O(N)
GridLayout将其需求转换为形式的线性约束系统:
x[i] - x[j] < a[k]
这是线性规划问题的一个特例,它又等价于有向图上的单源最短路径问题,O(n^2)
Bellman-Ford算法是最常用的一般解
它有一个
solve
方法,该方法使用线性规划来保证其在给定配置的情况下必须满足的约束的一致性。如果找出与约束相关联的配置并将其删除,则可能可以提高布局性能。然后,解算器将不必解决它不能满足的问题,并将其自身移除。我通过对GridLayout的宽度使用wrap\u content
而不是match\u parent
,解决了这个问题,我想这对它来说少了一个需要担心的约束。对于我来说,我使用GridLayout创建了一个自定义视图
问题是我认为可以在xml中设置网格的列数
我的布局XML如下所示:
<merge xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
app:alignmentMode="alignMargins"
app:columnCount="9"
app:columnOrderPreserved="true"
tools:ignore="HardcodedText"
app:orientation="horizontal"
tools:parentTag="androidx.gridlayout.widget.GridLayout"
app:rowOrderPreserved="true">
...
</merge>
class SimpleCalculatorView(context: Context, attrs: AttributeSet?): GridLayout(context, attrs) {
init {
...
View.inflate(context, R.layout.view_simple_calculator, this)
columnCount = 9
columnOrderPreserved = true
rowOrderPreserved = true
orientation = HORIZONTAL
}
这样做之后,我就不再犯错误了
编辑
我说得太快了。错误再次出现,这一次每当我在motionlayout中设置自定义布局的动画时,它就开始发生。我尝试了这个,但似乎仍然有相同的问题。我没有使用兼容性库-这可能是不同之处。谢谢。希望对你有帮助
class SimpleCalculatorView(context: Context, attrs: AttributeSet?): GridLayout(context, attrs) {
init {
...
View.inflate(context, R.layout.view_simple_calculator, this)
columnCount = 9
columnOrderPreserved = true
rowOrderPreserved = true
orientation = HORIZONTAL
}