mmin18 / flexlayout Goto Github PK
View Code? Open in Web Editor NEWA powerful Android layout view that use java expression in layout params to describe relative positions.
License: Other
A powerful Android layout view that use java expression in layout params to describe relative positions.
License: Other
我给子控件添加了属性 android:visibility="gone",结果控件隐藏了,但控件仍然占用了空间,效果是跟 android:visibility="invisible"一样的
TextViiew设置layout_top和layout_bottom后,设置gravity无法居中。
如:
<TextView android:background="@color/color4" android:gravity="center" android:text="这是TextView" app:layout_height="this.width*0.2"a app:layout_centerY="50%" app:layout_left="20%" app:layout_centerX="50%" app:layout_right="90%" app:layout_bottom="prev.top" app:layout_top="view1.bottom"/>
即:同时设置android:layout_height 和 :layout_bottom、layout_top
实际显示高度按app:layout_bottom、app:layout_top显示,但是内部居中是按android:layout_height显示
除非删除android:layout_height 才正常显示
<TextView
android:text="Long text long text long text long text long text long text long text long text long text long text long text END"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="@color/color2"
app:layout_top="30dp"
app:layout_left="30dp"
app:layout_right="parent.width"
/>
当布局已指定该TextView的left 、right时,宽度仍然以parent的宽度测量导致显示异常。已提交pull requests修复该问题。
MD里padding和margin最好是8的倍数
Layout code:
<com.github.mmin18.widget.FlexLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="wrap_content"
>
<TextView
app:layout_width="min(wrap_content, 100% - 55dp)"
android:layout_height="wrap_content"
android:text="Hello World! Hello World! Hello World! Hello World! Hello World! Hello World! Hello World! Hello World! Hello World! Hello World! Hello World! Hello World! Hello World! Hello World! Hello World! Hello World! Hello World! Hello World! Hello World! Hello World! Hello World! Hello World! Hello World! Hello World! Hello World! End"
/>
<ImageView
android:layout_width="55dp"
android:layout_height="55dp"
app:layout_right="100%"
/>
</com.github.mmin18.widget.FlexLayout>
text got clipped (End
not visible):
Reference previous view using
prev
, next view usingnext
"Previous" and "next" in terms of... what?
app:layout_left="prev.right"
, prev
means "whatever's closest to us on the left")The rest of the rules seem straight-forward, but IMHO this description could use a bit more love.
Thanks!
Please can you add Anno (Kotlin) features for you lib?
Hi
When I am trying to set views relatively to each other I a getting following error. I have taken care of defining references view first.
I am using Android studio 2.0. I am facing this issue in my demo app as well as sample app along with this library.
(Reference a specific view using view's id)
java.lang.IllegalArgumentException: unknown identifier view2, layout_top=view2.bottom+20dp
at com.github.mmin18.widget.FlexLayout$TokenReader.parseStr(FlexLayout.java:1334)
at com.github.mmin18.widget.FlexLayout$TokenReader.readToken(FlexLayout.java:1286)
at com.github.mmin18.widget.FlexLayout$RPN.parse(FlexLayout.java:1420)
at com.github.mmin18.widget.FlexLayout$LayoutParams.(FlexLayout.java:78)
at com.github.mmin18.widget.FlexLayout.generateLayoutParams(FlexLayout.java:325)
at com.github.mmin18.widget.FlexLayout.generateLayoutParams(FlexLayout.java:32)
at android.view.LayoutInflater.rInflate_Original(LayoutInflater.java:837)
at android.view.LayoutInflater_Delegate.rInflate(LayoutInflater_Delegate.java:70)
at android.view.LayoutInflater.rInflate(LayoutInflater.java:811)
at android.view.LayoutInflater.rInflateChildren(LayoutInflater.java:798)
at android.view.LayoutInflater.inflate(LayoutInflater.java:515)
at android.view.LayoutInflater.inflate(LayoutInflater.java:394)
at com.android.layoutlib.bridge.impl.RenderSessionImpl.inflate(RenderSessionImpl.java:229)
at com.android.layoutlib.bridge.Bridge.createSession(Bridge.java:426)
at com.android.ide.common.rendering.LayoutLibrary.createSession(LayoutLibrary.java:350)
at com.android.tools.idea.rendering.RenderTask$2.compute(RenderTask.java:510)
at com.android.tools.idea.rendering.RenderTask$2.compute(RenderTask.java:498)
at com.intellij.openapi.application.impl.ApplicationImpl.runReadAction(ApplicationImpl.java:967)
at com.android.tools.idea.rendering.RenderTask.createRenderSession(RenderTask.java:498)
at com.android.tools.idea.rendering.RenderTask.access$600(RenderTask.java:72)
at com.android.tools.idea.rendering.RenderTask$3.call(RenderTask.java:610)
at com.android.tools.idea.rendering.RenderTask$3.call(RenderTask.java:607)
at com.android.tools.idea.rendering.RenderService.runRenderAction(RenderService.java:359)
at com.android.tools.idea.rendering.RenderTask.render(RenderTask.java:607)
at com.android.tools.idea.rendering.RenderTask.render(RenderTask.java:629)
at com.intellij.android.designer.designSurface.AndroidDesignerEditorPanel$7.run(AndroidDesignerEditorPanel.java:519)
at com.intellij.util.ui.update.MergingUpdateQueue.execute(MergingUpdateQueue.java:337)
at com.intellij.util.ui.update.MergingUpdateQueue.execute(MergingUpdateQueue.java:327)
at com.intellij.util.ui.update.MergingUpdateQueue$3.run(MergingUpdateQueue.java:271)
at com.intellij.util.ui.update.MergingUpdateQueue.flush(MergingUpdateQueue.java:286)
at com.intellij.util.ui.update.MergingUpdateQueue.flush(MergingUpdateQueue.java:244)
at com.intellij.util.ui.update.MergingUpdateQueue.run(MergingUpdateQueue.java:234)
at com.intellij.util.concurrency.QueueProcessor.runSafely(QueueProcessor.java:238)
at com.intellij.util.Alarm$Request$1.run(Alarm.java:352)
at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:439)
at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:303)
at java.util.concurrent.FutureTask.run(FutureTask.java:138)
at java.util.concurrent.ThreadPoolExecutor$Worker.runTask(ThreadPoolExecutor.java:895)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:918)
at java.lang.Thread.run(Thread.java:695)
Here is my sample XML file...
<com.github.mmin18.widget.FlexLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent">
<Button
app:layout_width="(152/3.84)%"
app:layout_height="(64/5.70)%"
android:text="New Button"
android:id="@+id/button"
app:layout_centerX="50%"
app:layout_top="(73.68%)"/>
<ImageView
app:layout_width="(116/3.84)%"
app:layout_height="(94/5.70)%"
app:layout_top="(25/5.70)%"
app:layout_left="0dp"
android:id="@+id/imageView2"
android:background="@color/abc_search_url_text_pressed"/>
<TextView
android:id="@+id/view2"
app:layout_width="(244/3.84)%"
app:layout_height="(32/5.70)%"
android:text="New Text1"
app:layout_left="(122/3.84)%"
app:layout_top="(32/5.70)%"/>
<TextView
android:id="@+id/textView3"
android:layout_width="244dp"
android:layout_height="32dp"
android:text="New Text"
app:layout_centerX="view2.centerX"
app:layout_top="view2.bottom+20dp"
/>
</com.github.mmin18.widget.FlexLayout>
Let me know if I am missing anything.
使用类似 readme 中的
app:bottom="50%-@dimen/default_margin"
app:width="2*@android:dimen/app_icon_size"
会无法预览, 提示can`t resolve symbol
Android Studio 2.2 has introduced the New UI Designer & Constraint Layout, but in the preview tab of AS, it can't preview my layout, the stack trace is:
java.lang.NoSuchFieldError: FlexLayout_Layout
at com.github.mmin18.widget.FlexLayout$LayoutParams.<init>(FlexLayout.java:104)
at com.github.mmin18.widget.FlexLayout.generateLayoutParams(FlexLayout.java:353)
at com.github.mmin18.widget.FlexLayout.generateLayoutParams(FlexLayout.java:36)
at android.view.LayoutInflater.rInflate_Original(LayoutInflater.java:860)
at android.view.LayoutInflater_Delegate.rInflate(LayoutInflater_Delegate.java:70)
at android.view.LayoutInflater.rInflate(LayoutInflater.java:834)
at android.view.LayoutInflater.rInflateChildren(LayoutInflater.java:821)
at android.view.LayoutInflater.inflate(LayoutInflater.java:518)
at android.view.LayoutInflater.inflate(LayoutInflater.java:397)
at com.android.layoutlib.bridge.impl.RenderSessionImpl.inflate(RenderSessionImpl.java:317)
at com.android.layoutlib.bridge.Bridge.createSession(Bridge.java:429)
at com.android.ide.common.rendering.LayoutLibrary.createSession(LayoutLibrary.java:389)
at com.android.tools.idea.rendering.RenderTask$2.compute(RenderTask.java:548)
at com.android.tools.idea.rendering.RenderTask$2.compute(RenderTask.java:533)
at com.intellij.openapi.application.impl.ApplicationImpl.runReadAction(ApplicationImpl.java:962)
at com.android.tools.idea.rendering.RenderTask.createRenderSession(RenderTask.java:533)
at com.android.tools.idea.rendering.RenderTask.lambda$inflate$58(RenderTask.java:659)
at com.android.tools.idea.rendering.RenderService.runRenderAction(RenderService.java:380)
at com.android.tools.idea.rendering.RenderTask.inflate(RenderTask.java:659)
at com.android.tools.idea.uibuilder.model.NlModel.inflate(NlModel.java:327)
at com.android.tools.idea.uibuilder.model.NlModel.render(NlModel.java:384)
at com.android.tools.idea.uibuilder.editor.NlPreviewForm$Pending.<init>(NlPreviewForm.java:234)
at com.android.tools.idea.uibuilder.editor.NlPreviewForm.setFile(NlPreviewForm.java:293)
at com.android.tools.idea.uibuilder.editor.NlPreviewManager$3.run(NlPreviewManager.java:290)
at com.intellij.util.ui.update.MergingUpdateQueue.execute(MergingUpdateQueue.java:333)
at com.intellij.util.ui.update.MergingUpdateQueue.execute(MergingUpdateQueue.java:323)
at com.intellij.util.ui.update.MergingUpdateQueue$3.run(MergingUpdateQueue.java:267)
at com.intellij.util.ui.UIUtil.invokeLaterIfNeeded(UIUtil.java:2440)
at com.intellij.util.ui.update.MergingUpdateQueue.flush(MergingUpdateQueue.java:279)
at com.intellij.util.ui.update.MergingUpdateQueue.run(MergingUpdateQueue.java:234)
at com.intellij.util.concurrency.QueueProcessor.runSafely(QueueProcessor.java:238)
at com.intellij.util.Alarm$Request$1.run(Alarm.java:378)
at com.intellij.util.Alarm$Request.run(Alarm.java:398)
at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:511)
at java.util.concurrent.FutureTask.run(FutureTask.java:266)
at com.intellij.util.concurrency.SchedulingWrapper$MyScheduledFutureTask.run(SchedulingWrapper.java:227)
at java.awt.event.InvocationEvent.dispatch(InvocationEvent.java:311)
at java.awt.EventQueue.dispatchEventImpl(EventQueue.java:756)
at java.awt.EventQueue.access$500(EventQueue.java:97)
at java.awt.EventQueue$3.run(EventQueue.java:709)
at java.awt.EventQueue$3.run(EventQueue.java:703)
at java.security.AccessController.doPrivileged(Native Method)
at java.security.ProtectionDomain$JavaSecurityAccessImpl.doIntersectionPrivilege(ProtectionDomain.java:76)
at java.awt.EventQueue.dispatchEvent(EventQueue.java:726)
at com.intellij.ide.IdeEventQueue.defaultDispatchEvent(IdeEventQueue.java:857)
at com.intellij.ide.IdeEventQueue._dispatchEvent(IdeEventQueue.java:658)
at com.intellij.ide.IdeEventQueue.dispatchEvent(IdeEventQueue.java:386)
at java.awt.EventDispatchThread.pumpOneEventForFilters(EventDispatchThread.java:201)
at java.awt.EventDispatchThread.pumpEventsForFilter(EventDispatchThread.java:116)
at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:105)
at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:101)
at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:93)
at java.awt.EventDispatchThread.run(EventDispatchThread.java:82)
<TextView
android:id="@+id/View1"
app:layout_width="min(wrap_content, 100%-next.width-prev.width)"
android:layout_height="wrap_content"
android:ellipsize="end"
android:maxLines="1"
app:layout_left="prev.right"
app:layout_right="next.left"
app:layout_top="prev.top" />
当布局是这种定位的时候该TextView最后不显示(应该是同时定义了layout_left和layout_right的原因),只定义layout_left,在下一个View里也定义layout_left则可以生效
其实这不是一个 issue 😃
首先点12个赞,FlexLayout 真的太棒了!
我对 RelativeLayout, FlexLayout 以及其他 layout 实现同样的 UI 的性能进行了一个测试,测试结果传送门:http://blog.piasy.com/2016/04/07/Layout-Perf/,总的来说,非列表情况下,FlexLayout 的性能几乎毫不逊色,但如此强大优雅的方式,何乐而不用呢!
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.