I have a horizontalScrollView with a listview in it. I add multiple custom RelativeLayouts to this, each one contains two TextViews, vertically.
The top TextView will always be visible and will have a small amount of text, things like S,M,L,XL,XXL.
The bottom TextView will only display when the top one is selected. The text in this will be much bigger though, e.g. Low in Stock, Out of Stock etc.
Because the bottom TextView is bigger, it is forcing the gap between each RelativeLayout to be different depending on the text in the bottom TextView.
I would like the distance to be equal between each RelativeLayout and as there will only ever be one bottom TextView visible at one time, I would like that text to potentially span beneath multiple top TextViews.
Is this possible? At the moment, I can't find anything that will help.
I have included an image. The top is what I have, with the bottom TextView size dictating the overall space. The bottom image is what I'd like, with the bottom Text overflowing beneath the top Text when it needs to.
UPDATE: #mikejonesguy, roughly what I have is (psuedocode)
<Relative Layout>
<TextView
android:id="#+id/id1"/>
<TextView
android:layout_below="#id/id1"/>
</Relative Layout>
Related
I cant move any elements in the layout (android studio) for some reason..
I searched alot and nothing worked with me.
All text views or buttons (all elements) stays top-left and I cant move them or even resize them...
Whats the solution for that?
And if I tried to resize the button it fills up the whole screen.
thats the code view
This is happening as you have used constraint layout in your XML file.
and the constraints as you have given in your file that makes your elements stay up at the top left.
Solution 1:
When you give start to start constraint to the parent and end to end constraint to the parent it makes your view to stick to the both side of the screen.
Even if you have given your view's height and width to wrap content it will be considered as match parent.
<androidx.constraintlayout.widget.ConstraintLayout ...>
<Button android:id="#+id/button" ...
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"/>
</>
as This will make your view to stretch to the both side of the screen and will take whole space horizontally.
all you need to do is remove the constraints mentioned below:
if you want to let your view to stick to the left side of the screen-
Remove EndtoEndof = parent constraint
if you want to let your view to stick to the right side of the screen-
Remove StarttoStartof = parent constraint
The issue with resizing the button is that you have given the constraints to the view to stick to bottom and top of the screen so it will take up whole screen vertically.
if you want to make your button to stay to the bottom
Remove toptotopof = parent
if you want to make your button to stay to the top
Remove bottomtoBottomof= parent
all you need is to understand how constraint layout works .
Look into this link it will help you understand the constraint layout from broad perspective.
One multiline textview and an another custom view are aligned horizontally in a linear layout. Height of custom view is 100dp. What I want to achieve is to expand width of lines of multiline textview which are below custom view to match parent.
This is a rough sketch of what I want to implement.
Is there any way to achieve this?
I have a recyclerview with bunch of textview each as an item as you see in picture below. (Blue lines aren't really there, i added them so you can see each item separately) as you can see everything seems nice and user will not notice the text is separated.
The problem is when user increases the line space(a typical option in app) line height gets bigger except the first and last line of each item and the result seems like second picture.
My question is how to find appropriate padding to set to each item so every line height seen exactly the same?
BTW i can not use just one textview for many reason!
You can increase the divider height of your listview according to linespacing height.
Or you can set an invisible view at the bottom of every row item and increase the height of this view according to linespacing height.
Or you can set padding at the bottom of every row item and increase the value of this padding according to linespacing height.
just add some padding to the parent of your textview in the layout file of your list item .
for example the layout with linearlayout would be like :
<LinearLayout ........
paddingTop=15dp>
<TextView
..........>
</TextView>
</LinearLayout>
and you could adjust the padding dynamically if you want.
Im running into a speed bump in my android App. I want to center my Linear Layout in the center of the screen (Horisontally only) and I want to center another element only vertically. I haven't seen an easy apparent way to do this in the program.
http://i.stack.imgur.com/gfMBD.png
I want the grey Box to be centered horisontally in the app
I'm not sure, how your layouts are now, but I'd do something like this:
Vertical Linearlayout
RelativeLayout, centered horizontally
RelativeLayout, set to match parent
RelativeLayout, centered vertically
Use RelativeLayout as a root ViewGroup, and then just add android:layout_centerHorizontal="true" to your first LinearLayout, and android:layout_centerVertical="true" to your second one.
I have a simple problem but could not solve it with clean solution .
Suppose there are two textviews horizontally next to each other. I want to make them such that
second textview come just right to first and first should grow as much as it can without putting second textview out of screen (means second textview should always be visible).
Hint:you could always use Relative layout and try scaling them in the Graphical layout.
One solution would be, putting the two textViews in a LinearLayout and assign each textView a weight attribute. The LinearLayout divides the space between those views accordingly to the weight. For example if the first textview has weight 3 and the second has weight 2, the width for the first textview would be 3/5 superviews width and the second would be 2/5.
Another solution would be to put the second textView with a fixed width aligned right to the parent RelativeLayout, and the first view to be leftof the second view with the width 'match_parent'