协调器布局TextInput在FloatingActionButton下面(Coordinator layout TextInput below FloatingActionButton)
Halloo伙计们我在协调员布局方面遇到问题。 我有TextInputLayout,在里面我有editText。 我想要的是点击左侧的FAB显示它并隐藏点击FAB。
但我总是有问题编辑文本在FAB下面:
只有我能够以某种方式做到这一点是使用
marginRight
,请参阅下面的xml。 但是没有任何方法可以做到这一点我认为必须有更好的方法。<android.support.design.widget.FloatingActionButton android:id="@+id/fab" android:layout_width="@dimen/fab_normal_size" android:layout_height="@dimen/fab_normal_size" android:layout_gravity="bottom|end" android:layout_margin="@dimen/fab_margin" app:fabSize="normal" android:src="@drawable/ic_add_black_24dp" /> <android.support.design.widget.TextInputLayout android:id="@+id/input_layout_txt" android:layout_width="match_parent" android:layout_height="wrap_content" app:layout_anchor="@id/fab" app:layout_anchorGravity="left|center_vertical" android:layout_marginRight="@dimen/fab_normal_size"> <EditText android:id="@+id/input_txt" android:layout_width="match_parent" android:layout_height="wrap_content" android:hint="banany" android:text="testestes....." />
Halloo guys I have problem here with coordinator layout. I have TextInputLayout and inside it I have editText. What I want is to show it on click on FAB on the left side and hide on click on FAB.
But I have always problem with edit text going below FAB:
Only way I was able to somehow do it is with using
marginRight
, see xml below. But is there any way to do it without that I think there must be better way.<android.support.design.widget.FloatingActionButton android:id="@+id/fab" android:layout_width="@dimen/fab_normal_size" android:layout_height="@dimen/fab_normal_size" android:layout_gravity="bottom|end" android:layout_margin="@dimen/fab_margin" app:fabSize="normal" android:src="@drawable/ic_add_black_24dp" /> <android.support.design.widget.TextInputLayout android:id="@+id/input_layout_txt" android:layout_width="match_parent" android:layout_height="wrap_content" app:layout_anchor="@id/fab" app:layout_anchorGravity="left|center_vertical" android:layout_marginRight="@dimen/fab_normal_size"> <EditText android:id="@+id/input_txt" android:layout_width="match_parent" android:layout_height="wrap_content" android:hint="banany" android:text="testestes....." />
原文:https://stackoverflow.com/questions/37121028
最满意答案
你最大的问题不是循环。 对于矩阵这么小的调用MATLABs
A*B
引入了很多开销。 您可以做的最好的事情是将所有矩阵存储在一个大的4 x n_matrices
矩阵中并手动拼出矩阵乘法:A = rand(4, 1000); B = rand(4, 1000); tic; C = zeros(size(A)); C(1,:) = A(1,:).*B(1,:) + A(3,:).*B(2,:); C(2,:) = A(2,:).*B(1,:) + A(4,:).*B(2,:); C(3,:) = A(1,:).*B(3,:) + A(3,:).*B(4,:); C(4,:) = A(2,:).*B(3,:) + A(4,:).*B(4,:); toc Elapsed time is 0.020950 seconds.
如您所见,这需要很少的时间(这是一台6年的台式PC)。 对于像这样的小矩阵来说这是实用的,我无法想象用MATLAB编写的其他任何可以击败这种性能的东西。 好吧,对于非常大量的
2x2
矩阵,您可以引入阻塞(即,一次只处理多个矩阵)以增强缓存重用。Your biggest problem is not the loops. For matrices so small calling MATLABs
A*B
introduces a lot of overhead. The best thing you can do is to store all the matrices in a large4 x n_matrices
matrix and spell out the matrix multiplications manually:A = rand(4, 1000); B = rand(4, 1000); tic; C = zeros(size(A)); C(1,:) = A(1,:).*B(1,:) + A(3,:).*B(2,:); C(2,:) = A(2,:).*B(1,:) + A(4,:).*B(2,:); C(3,:) = A(1,:).*B(3,:) + A(3,:).*B(4,:); C(4,:) = A(2,:).*B(3,:) + A(4,:).*B(4,:); toc Elapsed time is 0.020950 seconds.
As you see, this takes little time (this is a 6-years old desktop PC). For small matrices like this it is practical and I can not imagine anything else written in MATLAB that could beat this performance-wise. Well, for very large number of
2x2
matrices you could introduce blocking (i.e., handle only a number of matrices at a time) to enhance cache reuse.
相关问答
更多-
这是我的结果,使用MATLAB R2011a + 并行计算工具箱在一台具有特斯拉C2070的机器上: >> A = rand(1024); gA = gpuArray(A); % warm up by executing the operations a couple of times, and then: >> tic, C = A * A; toc Elapsed time is 0.075396 seconds. >> tic, gC = gA * gA; toc Elapsed time is 0. ...
-
矩阵矩阵在matlab中(Matrix of matrices in matlab)[2023-02-07]
使用单元阵列。 喜欢这个 c = cell(3,3) %Create cell array of size *3x3* c = [] [] [] [] [] [] [] [] [] c{1,1}; = rand(3,3); %Set cell {1,1} to be random matrix of size *3x3* c{1,2} = ones(4,6) %Set cell {1,2} to be matrix of ones si ... -
由于矩阵乘法在Matlab中高度优化,所以在底层使用LAPACK库。 你会发现很难击败那些图书馆的表现。 当然,简单的嵌套循环不会考虑缓存效果 ,因此会表现出糟糕的性能。 Because matrix multiplication is highly optimised in Matlab, using LAPACK libraries under the hood. You will find it hard to beat the performance of those libraries. Cert ...
-
你最大的问题不是循环。 对于矩阵这么小的调用MATLABs A*B引入了很多开销。 您可以做的最好的事情是将所有矩阵存储在一个大的4 x n_matrices矩阵中并手动拼出矩阵乘法: A = rand(4, 1000); B = rand(4, 1000); tic; C = zeros(size(A)); C(1,:) = A(1,:).*B(1,:) + A(3,:).*B(2,:); C(2,:) = A(2,:).*B(1,:) + A(4,:).*B(2,:); C(3,:) = A(1,:) ...
-
你有两个问题: 在Python中,您可以计算随机初始化以及计算,而Fortran和MATLAB则不然 在Fortran中,您可以在Python和MATLAB中测量经过的时间来测量CPU时间。 而且由于您注意到CPU使用率约为46%,这可能只是解释了差异。 只需修复这两件事date_and_time()试......您可以考虑使用date_and_time()而不是cpu_time()来实现此目的。 You have two issues here: In Python, you time the rando ...
-
正如评论中所提到的, bsxfun可以在重塑B之后使用,就像这样 - squeeze(sum(bsxfun(@times,reshape(B,size(A,2),[],size(B,2)),A.'),1)) As mentioned in the comments, bsxfun could be used after reshaping B, like so - squeeze(sum(bsxfun(@times,reshape(B,size(A,2),[],size(B,2)),A.'),1))
-
Matlab:基于子矩阵重塑大矩阵的最佳方法是什么?(Matlab: what is the best way to reshape a large matrix based on sub-matrices)[2021-12-31]
Matlab的reshape功能非常方便(快速),但总是读写完整的列。 因此,对于您的问题,还需要一些额外的步骤。 以下是如何做到这一点: m = 5 % columns of submatrix n = 4 % rows of submatrix k = 50 % num submatrixes in matrix column l = 50 % num submatrixes in matrix row A = rand(m*k,n*l); % rand(250,200) 将矩阵重新整形为四维矩阵(维 ... -
这是一种方式: C = bsxfun(@times, A, B) 根据文档 ,得到的矩阵C是稀疏的: 如果两个操作数都是稀疏的,则二元运算符产生稀疏结果,如果两个操作数都是满的,则产生完整结果。 对于混合操作数,除非操作保留稀疏性,否则结果将为完整 。 如果S稀疏且F满,则S + F,S * F和F \ S满, 而S. * F和S&F稀疏 。 在某些情况下,即使矩阵的零元素很少,结果也可能是稀疏的。 Here's one way: C = bsxfun(@times, A, B) According t ...
-
首先:我假设nnz(A)相当低。 我刚用nnz(A) = 9999963测试了它,并且size(A) = 1000000x1000000 。 直观的方法是使用“块”中的数据。 取前10000列(所有行)和前10000行(所有列),下一个10000,下一个等。我相信这应该避免内存问题。 我刚刚测试了A*A ,并且遇到了和你一样的内存问题。 我做的是,将A转换为逻辑: A_logical = logical(A) 。 这大大减少了矩阵的大小。 注意,您不能使用uint8或类似的东西,因为sparse支持的唯一数 ...
-
您正在尝试计算每行的外积,并将其自身存储为3D矩阵中的单个切片。 你的代码几乎可以工作 你正在做的是计算每行的内积或点积。 因此它会给你一个数字而不是矩阵。 您需要更改转置操作,以便在P1上完成,而不是P2 , P2现在只需P1 。 此外,您在每次迭代时都会覆盖矩阵M 我假设您想将这些作为单个切片存储在3D矩阵中。 为此,请分配一个3D矩阵,其中每个2D切片具有相同数量的行和列,这是D的列数,而切片总数等于D的总行数。 然后只需索引到每个切片并相应地放置结果: M = zeros(size(D,2), si ...