android


Horizontal LinearLayout with Multiple Children, Move Children Below on New Line When No More Horizontal Space


I would like to have a horizontal LinearLayout that is as wide as the screen and as high as its children, but the trick is that its children will have dynamic width each and I don't want them going off screen (cut out). I want them to flow/break in a new line so that they are all visible.
Although totally irrelevant to Android, it should work similar to how inline <div>'s work in HTML.
Here's what I have right now:
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="If you would enter some digits in this field " />
<EditText
android:id="#+id/tvDistance"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:hint="enter some digits here"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text=" that would be great" />
</LinearLayout>
But as soon as the children of the LinearLayout get wider than the screen the extra part gets off the screen/invisible.
I would like to have a horizontal LinearLayout that is as wide as the
screen and as high as its children, but the trick is that its children
will have dynamic width each and I don't want them going off screen
(cut out).
A LinearLayout can't do that(any default layout from the SDK can't do that) because the LinearLayout is set to place all the children in one horizontal or vertical line. Also, any type of conditional layout rules based on dimensions not yet available(like in your case the available width for the LinearLayout) are not possible in the xml anyway.
What you need is a custom layout which measures the children to use the available space moving any non fitting children on a new line below(a FlowLayout). You have an example of such a layout, from one of the engineers working on Android, in this video. There are also other implementations out there to have a look at(implementing such a layout isn't hard anyway).

Related Links

How to compile IFCPlusPlus code using android CMake
FrameLayout setOffscreenPageLimit?
The system crash when go out from the activity
Required attribute for the selector tag?
Can I change distance between icon and item title in Navigation Drawer?
Alt/Enter to import missing classes
Android Firebase Nested Query
Drawer Nav and Fragments?
Android CharSequence[] Array Doesn't work
Does Firebase change app key hash for Facebook?
LRUCACHE in custom gridview
How to prevent my android activity from going to isFinishing()?
How can i create Andriod Virtual Device (AVD) on Mac Sierra
AES/CBC/PKCS5 Padding and MD5 in iOS and Android
VideoView to Display Embeded Video
how to retrieve blocked google play account

Categories

HOME
batch-file
toolbox
spring-data-redis
access
seo
edge
simulink
scripting
interpolation
google-cloud-datalab
azure-container-service
trac
g++
octave
resultset
why3
angular-dart
favicon
pybossa
dreamweaver
string-concatenation
interpreter
dynamically-generated
mount
moses
motion-detection
angularjs-components
asymptotic-complexity
alm
kudu
weather
gojs
jwplayer6
imx6
sharepoint-workflow
sim-toolkit
connection-pool
chef-solo
urlsession
odoo-website
logback-groovy
clang++
vaadin-charts
fwrite
openresty
lampp
automapper-5
compiler-design
filehandle
pybrain
renaming
rmongo
change-tracking
materialized-path-pattern
smartfoxserver
cubism.js
xcode-server
model-associations
expectations
dimension
xdoclet
udpclient
android-wake-lock
lua-telegram-bot
ikiwiki
fuzzywuzzy
grass
blitline
wiredep
lazybones
django-urls
dronekit-android
linked-tables
qtwebengine
cosine-similarity
post-commit-hook
formview
encryption-asymmetric
mutual-authentication
vbe
breakout
beaker-testing
flex++
node-blade
virtual-pc
jquery-blockui
saleslogix
garbage
mapping-by-code
azman
jquery-address
node-redis
user-tracking
htdocs
msr
qglwidget
delimited-text
spread
filesystemobject
silverlight-oob
alsb
firefox-3
dsoframer
leader

Resources

Encrypt Message