I write a rectangle widget.
After writing its portrait XML, I want to write its landscape.
I should change any LinearLayout orientation from horizontal to
vertical?
horizontal is right to left (not top to bottom) relative to the
screen in origin portrait mode?
If i don't mention layout_height property, what is the default?
(match parent?)
how does weight property take effect when I specify
layout_width = X dip?
when I specify layout_width = wrap_content?
what does fill_parent mean when in top-most LinearLayout?
1a) No, you should not.
1b) Horizontal is left to right relative to the screen in origin portrait mode.
2) There is no default value, you have to set it (other time you will see an error)
3) Please look at that question
4) The view should be as big as its parent (minus padding)
To give the task of managing screen orientation to Android on behalf, you don't need to think all this stuff. Just mention android:configChanges="orientation|keyboardHidden|screenSize|screenLayout" in your activity from AndroidManifest.xml
Related
I want to change the height of a LinearLayout and works everything OK, but I want height decreasing and increasing from the top (the defaults starts decreasing and increasing from the bottom).
Here is an example:
LinearLayout linearLayout = findById(R.id.layout);
LinearLayout.LayoutParameters layoutParams = (LinearLayout.LayoutParameters) linearLayout.getLayoutParams();
layoutParams.height = linearLayout.getHeight() - 1;
linearLayout.setLayoutParams(layoutParams);
This works OK. The only thing I wanna change is the direction of height change.
Thanks for the replay.
You can achieve this by binding(the bottom) of your linear layout inside a constraint layout,
Also is there a parent to your linear layout?, if so then it being unbound might be the reason
I achieved changing the direction with the setLayoutDirection(View.LAYOUT_DIRECTION_LOCALE) from teh ViewGroup class. Also had to change layout's gravity to bottom in the xml.
Thanks for contribute to my answer.
How do I go about setting the background for a splash screen that does not stretch, and maintains a density-independent size? Here's a visual of what I'm trying to go for:
I have a large image file (1000x1000px) of the background. I want the background to maintain its density-independent size, with the excess just not visible, so that it will be displayed correctly on various screen sizes. I also want the center of the image anchored to the center of the screen. (the image above is just a mockup, the focal point should be at the center of the image)
How do I do this?
You have a link here in stackoverflow that might help.
You can use an ImageView as your background (otherwise backgrounds of any view will just stretch).
And use it as the background of your ImageView. Your ImageView can then have the layout_width and the layout_height as wrap_content.
Then, set the ScaleType as android:scaleType="centerCrop".
Note that this ImageView has to be the first element of your layout. Otherwise it will just hide everything in your layout.
I'm new to Android but i have a simple problem.
I have a vertical linear layout, if i place here a normal button, and give it the MATCH_PARENT flag for the width and the height, the button will fill all the space. All ok.
Now i have a my simple custom view (a class that extends View) and i overrided the OnDraw method for draw a cross in the middle of the view. For draw the cross i need to get the width and the height of the control, if in the UI Layout editor of eclipse i set a fixed width and height, it works correcly (i see a preview of the cross directly in Eclipse) but if i extend the View to the borders i got only WARP_CONTENT (With button i get MATCH_PARENT), no problem, i change it in the XML, but LayoutParams width and height will return 0!! (I see the error directly in the preview of eclipse!) Why?
I tried to set manualy the width and the height in the OnWindowFocusChanged method to wait but it give me always 0.
The problem is that the view actualy have the rights dimensions but when i call the getLayoutParams().width it give me 0, so i see a white rectangle in the right position (white background of the view), but the cross is drawed on the upper-left corner!
Sorry for my bad english.
Thank you.
Mauro.
i think u need to set this parameter for your view.
android:layout_alignTop
or something related to this.i guess
I am attempting to create a textView that will take up a large portion of the top center part of the screen. Ideally, setting the text size in dp would allow the textView to remain the correct relative size (taking up about 70% of the width of the screen, and maybe 20% of the top). It looks correct in the layout editor, and in the emulator at HVGA resolution. However, when I test it at higher resolutions (on my tablet, or emulating a 720p display) the text takes up a very small portion of the top center part of the screen. (maybe 30% width instead of 70%, and it doesn't seem any larger vertically).
Is there a way to scale text to correctly increase relative size with resolution?
Set the layout_width as fill_parent, which will make it spread across the screen for all devices.
Add some padding on left right and top which seems suitable.
The padding might seem different for different screens but still this might be a better solution.
set
android:layout_width="match_parent"
edit:
check this out
Auto Scale TextView Text to Fit within Bounds
I'm having a problem with positioning images,I need to position a lot images over another larger background image.
An image Like this
I have tried Absolute but it does not keep the position of the image say I wanted to put a clip art image of a board pin over the background image and need it pointing at a sun and when it's clicked I get a popup dialog,
but then when I change the size of the emulator screen the clip art image is not at the same position I wanted it on the background image.
I first tried just putting the clip art on it with a image editor and used onTouch Listener but that didn't work out when I changed the size of the screen with the x and y coordinates. And tried Absolute Layout and that doesn seem to keep the position.
any ideas would help me big time thanks
AbsoluteLayout is deprecated, so it's probably best to use relative layout alongside with dp.
You could use relative layout so you can use layout_below="#id/view1", android:layout_toRightOf="#id/view2", and android:layout_toLeftOf="#id/view3". You can also use android:layout_marginLeft="10dip", android:layout_marginRight="10dip", android:layout_marginTop="10dip", and android:layout_marginBottom="10dip" to move the views left/right and up/down relative to their current positions. There is also ALIGN_PARENT_LEFT, ALIGN_PARENT_RIGHT, ALIGN_PARENT_TOP, and ALIGN_PARENT_BOTTOM. Click here for more properties.
You can manually calculate visible width and height of the image by using its drawable's getIntrinsicHeight() and getIntrinsicWidth() and then set Image's scaleType to FIT_XY (this saves image's ratio, and also makes its size correct, while FIT_CENTER does not).