Force layout to draw a view/layout - android

Have a look at the picture: the root layout is a LinearLayout, horizontal. It contains a TextView, the text can be pretty long (I use singleline andellipsize), then the image in the second column of the layout won't be visible. Is there a way to force the image/ its layout column to be drawn other than using fixed width values? For example let the layout be drawn from right to left?

Related

Position View based on where LinearLayout children touch

I have a layout like this. Colored green is a horizontal LinearLayout, blue is a vertical LinearLayout and black are EditTexts (whose width and height can change). The red line represents where the EditTexts in the blue LinearLayout touch.
What I'm trying to accomplish is align the outer EditTexts so that the red line is always in the vertical center of them. On the image it already looks like that since I set the layout's gravity to center, but my issue occurs when the height of one of the EditTexts in the blue layout is bigger that the other. It should look like this, but in reality it looks like this.
What I'm trying to achieve can be accomplished with ConstraintLayouts by constraining the outer EditText's top to the bottom of the top inner (inner meaning those which used to be in the blue layout) EditText and the bottom to the top of the bottom inner EditText, but then there are other issues
All EditTexts would be in the same layout which messes with the code a lot
You can constrain the end/start to only one other View and so one of the inner EditTexts would overlap the outer one (e.g. if the outer EditText was constrained to the top inner EditText, the bottom inner EditText would overlap the outer one if it were wider than the top one) Demonstration
Every View is created dynamically so using LinearLayouts makes locating each one way easier
How would you approach this issue?
There is no way to use just the XML for the layout you have to center the external EditTexts to the red line. ConstraintLayout is the way to go but, if that is not desirable, then you can apply translation to the external EditTexts. The idea is that you would measure the vertical location of the red line and the top position of each EditText. You would then apply enough translation in the Y direction to place the EditTexts where you want them
Se setTranslationY() and getY().

Android Dynamically changing one child Layout height

I wanted to make a layout which has three children layout.
the bottom layout must visible to bottom
screen size is enough:
the center layout need Dynamically change to wrap_content and we need the bottom layout is under the center layout (not top of the parent).
screen size is not enough:
fix size of center layout will fixed and it is a scrollview, it's height is dependency on the reminding width(if screen size is not enough)
I think a lot of ideas but i don't know how can do using xml. It can be only calculate in runtime?
this is the intend image:
you can use wrap_content in xml
OR
To change programatically you can use following code
Your_Layout.getLayoutParams().height = 100;

android app - make view only take up portion of parent view

I have a background image on my app, and I want my listview to be in the form of a window that overlays the background image. Sort of like the the form which has a white filter in this picture:
http://25.media.tumblr.com/ad75c4a9dad9650ed53d754712f4fbb2/tumblr_mgemxiU2W01r2wjwko2_1280.png
I currently have a listview defined in xml with:
android:layout_width="fill_parent"
android:layout_height="fill_parent"
and a semi transparent color as its background. This is great, but it takes up the whole screen, since it fills the parent width and height. What is the best way to make it slightly smaller than the parent's dimensions so that it is say, (fill_parent - some relative value) height and width?
Use margin in a layout to make it smaller relative to the parent layout and other child's
Use a FrameLayout as a parent, then add your ListView and set width and height to wrap_content. Now it should "float" above the other views inside the FrameLayout. You can use padding and margin to set its position.

Make last view fit to bottom of screen

is there any possibility to change the properties of the last view in the layout to change its size to fit to the bottom of the whole screen (in any screen density).
Here is a sample image of my layout:
The layout contains a ScrollView with a LinearLayout as only child. The last item in this LinearLayout is a TableView with a grey gradient as background.
You can try setting layout_height of your items to "fill_parent" and change their sizes via changing layout_weight property, that should work.
If you want the grey part to stick to the bottom you should put weight=1.0 and wrap content for height on the view that is above that one (the white area).
Checked it again on similar layout. The main work does the property android:fillViewport="true" Which
Defines whether the scrollview should stretch its content to fill the viewport
More infos: ScrollView.html#attr_android:fillViewport

Android - How to place an item on a layout relatively to the top?

How could I proceed to place an item on a LinearLayout, with a given space from the top? For instance, I would like to place the logo on the half of the top middle of the layout.
Thanks
There is no way to add percentages.
You can add two layouts with the same weight to split the screen in two and then add the logo with a centered gravity to the upper layout,
Or you can measure the screen and add the right amount of margins.
Use the paddingTop attribute of the view class.

Categories

Resources