I have a gallery in my app, is there a way change the position of it?
I tried android:gravity="center" but that did nothing. Cant get the gallery to move.
Also can the gallery be made bigger? By an exact size too? I don't want it to be fullscreen but i do want it to be bigger than it normally is. Close to fullscreen. Nothing i've done has changed it.
Any ideas?
Thanks in advance.
You can use layout_width and layout_height to set the size, the Gallery can be made to be pretty much any size you like. Usually you'll chose wrap_contents or fill_parent, but if you want to you can explicitly set the height to something such as 400dp and the width you would probably want to keep fill_parent. See declaring layout in Android docs for more info.
EDIT: Here is an example in XML:
<?xml version="1.0" encoding="utf-8"?>
<Gallery xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/gallery"
android:layout_width="fill_parent"
android:layout_height="400dp"
android:spacing="2px"
/>
Related
So I am trying to import a custom image as the background of an android app however it does not fill in all of the edges. The option I have seen is to set a second layout to be a frame layout and then place an image view within it with additional coding along the lines of android:scaleType="centerCrop". This will not fill the entire screen up for me however, heres a screenshot of what ends up happening -
Heres the xml code being used:
<FrameLayout
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical"
>
<ImageView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="#+id/backgroundImage"
android:background="#drawable/backgroundImgr"
android:scaleType="centerCrop"
/>
</FrameLayout>
Another issue is that different users use different resolutions so the background image has to be able to accommodate them all without being cut off. I'm not sure how to do this.
Set ScaleType fitXY and add android:adjustViewBounds ="true"
Please use android:src="#drawable/ instead background .I hope it will helps you.
Want to make space background to my activity and begin to rotate it slowly, but i stuck with that:
screenshot (http://postimg.org/)
The effect I need need I can get if add in XML file
android:scaleY="2"
android:scaleX="2"
but it will not work, android scale pic down when app start.
Guys, really need your help, I in android for 4 day and have bad english
----ADDED---
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent">
<ImageView android:id="#+id/image"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:src="#drawable/backgroundd"
android:layout_centerHorizontal="true"
android:layout_centerVertical="true"/>
</RelativeLayout>
I have not tried this, and I am not sure it is the best solution, but could you set a negative android:layout_marginon the image?
android:layout_margin="-100dp"
See here for more: How to get a view larger than its parent?
Also, posting your full XML could help us know more about how you are setting up the layout.
I am trying to have an image be fitted, and have a layout below it with some black background and whit text. My problem is that the layout ends up leaving space between the image and the text itself, and I don't understand why:
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content" >
<ImageView
android:id="#+id/image"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:scaleType="fitStart" />
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="15dp"
android:layout_below="#+id/image" >
<TextView
style="#style/text_overlay"
android:layout_width="match_parent"
android:layout_height="match_parent" />
<!-- Couple more elements -->
</RelativeLayout>
</RelativeLayout>
I would want this second RelativeLayout of 15dp touch the bottom of the image, but unless I change the image height to something small, it leaves some space. This layout specifies how to display an image + some text below it, but I have a total of 4 images that use this layout to get loaded on the screen, in a 2x2 display. (Each image takes 25% of the screen).
Any idea how to make the RelativeLayout align exactly with the bottom of the image please?
I do not fully understand your question though I think you might have a look at the launcher layout for my Newspaper Puzzles app...
http://code.google.com/p/newspaper-puzzles/source/browse/np/res/layout/launcher_layout.xml
or perhaps from the Open Sudoku Game look at the number pad layout found here:
http://code.google.com/p/newspaper-puzzles/source/browse/np/res/layout/s_im_numpad.xml
Use the ADT tools to get the right layout is probably best if possible but I know sometimes it is difficult to use to get specific results I still recommend using the xml tools included in the Android Development Tools.
http://developer.android.com/tools/help/adt.html#graphical-editor
I would recomend using a compound drawable if you're trying to put text directly below an ImageView.
See the following question for more details: How do I use a compound drawable instead of a LinearLayout that contains an ImageView and a TextView
First of all, can I just say, I find laying out android UI's to be a frustrating experience? I used to think the XML layouts were simple and clean and awesome but every time I try to make anything with it I spend hours trying to do the simplest things!
In this particular instance I'm trying to make a simple horizontal bar that contains an image button of fixed size on the right and to the left of it I want an ImageView that takes up the rest of the available width. I see similar constructs all the time in the UI: the search box that appears at the top of the screen when searching, the text area and send button for composing text/googletalk messages, etc.
I've tried both a horizontal linear layout and a relative layout, and I can't get the button to look right in either one. My latest attempt has the following layout code:
It looks like this:
Using the hiearchyviewer indicates that both the imageview and the button have the same height (45px). And it shows the view dimensions and positions to be exactly what I'm looking for. Same height (differing widths of course since the ImageView is much wider). And they butt right up next to each other, centered in the Relative Layout. However the button as drawn on screen is obviously not taking up the full ImageButton view. I'm thinking it's something weird about the android system 9patch drawable used for the ImageButton background. But what do I know? I can't get it to look right no matter what I try.
How did you set up your RelativeLayout? Try to set it up like this:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent" android:layout_height="wrap_content">
<ImageButton android:layout_width="wrap_content" android:src="#drawable/icon" android:layout_height="wrap_content" android:layout_alignParentRight="true" android:id="#+id/imgButton"></ImageButton>
<ImageView android:id="#+id/imageView2" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_alignParentLeft="true" android:src="#drawable/red_button" android:scaleType="fitXY" android:layout_alignBottom="#+id/imgButton" android:layout_alignTop="#+id/imgButton" android:layout_toLeftOf="#+id/imgButton"></ImageView>
</RelativeLayout>
Hope this helps.
If dimensions are exactly how you are looking for , then in ImageButton and ImageView , use android:scaleType="fitXY" and check.
For simple case , I might use linearlayout with horizontal orientation with two buttons in it with proper weights.
I have a widget layout xml which sets the src to the delivered android widget 4x1 frame image.Here is the widget layout code.
<?xml version="1.0" encoding="utf-8" ?>
<AbsoluteLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/tuwidget" android:layout_width="fill_parent"
android:layout_height="fill_parent">
<ImageView android:id="#+id/tuwidget_img_btn"
android:src="#drawable/widgetinitial"
android:layout_width="fill_parent"
android:layout_height="wrap_content" />
</AbsoluteLayout>
#drawable/widgetinitial holds the widgetinitial.png image example 4x1 at developer.android.com (AppWidget design guidelines).(4x1_Widget_Frame_Portrait.psd) What I am trying to do is display an image inside the delivered frame instead what happens is the frame image goes away and only the image I am trying to display shows up. How can I display the image inside the bounding box or the background?
Any help is much appreciated.
Another question - I think I saw in a couple of forums AbsoluteLayout is a deprecated feature for Android 2.1 and above. Is that correct? and does using AbsoluteLayout throws any force close or other exceptions?
AbsoluteLayout is deprecated. It doesn't throw any exceptions, but its generally a bad idea to use it because it is really hard to design a layout that will work on all screen sizes. There is generally a better way to do it using a different layout.
In your case, I don't follow exactly, but it sounds like you want to layer two widgets on top of each other? An image with a frame? To do so, I'd use a FrameLayout. This is designed for having multiple layers of images.
Common layout objects is also a good guide to the basic layout types.
Take a look at the end of the page 2 of this pdf