I want to display an image (image1 of 629x470 pixels) in a relative layout and use another complete white image (image2 of 1896x470 pixels) to scroll over image1 to hide/reveal image1.
My image1 is visible correctly. But image2 is automatically resized to a smaller version and positioned vertically centered to image1 due to which I am not able to completely coverup image1. How do I display image2 as is so that it completely covers image1?
adjustViewBounds and scaleType did not help.
My Layout is as follows:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent">
<ImageView android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:src="#drawable/image1" />
<ImageView android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="#drawable/image2" />
</RelativeLayout>
Please suggest.
If you want to use image2 to scroll over and cover up your image1, you may instead create custom layout(linearlayout type) for image2 and then call it up when you make events(scroll down etc.)
You may use android:layout_width="wrap_content" for image1 and use android:layout_width="match_parent" for image2 to set up their size.
The way you put imageview together in same xml will fix their position. Image2 will always stay under image1.
put some gravity for both images, e.g the below code will center them in center
android:layout_centerInParent="true"
or you can use
android:layout_gravity="center"
you can use other gravity options too, for more about gravity, refer to this link
http://developer.android.com/reference/android/view/Gravity.html
Related
I've got a problem with my application. I've a image which goes across the whole screen (ImageView) with this code in xml:
<ImageView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_alignParentRight="true"
android:src="#drawable/achtergrond"
android:scaleType="fitCenter" />
My problem is that the image is centered in the imageview itself. It needs to be centered up as you can see in the next picture:
The left image is what I have, with the image in the middle. The right is what I want, the image should be up in the whole layout, I need to set my image to match_parent to have it fill as background (I didn't set it as background because it would be stretched then).
I hope I'm missing something obvious! Thanks for helping me in advance!
<ImageView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:src="#drawable/achtergrond"
android:scaleType="fitStart" />
Essentially I'm looking for something like scaleType="centerCrop" without the center.
I am having trouble making an ImageView display correctly when it's larger than the screen dimensions. I'm trying to display an ImageView that starts top=0, left=0 and is not scaled. It's okay that the image does not fit on the screen. Right now I have it in a relative layout:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent">
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="#drawable/postagram_blank_large"/>
</RelativeLayout>
I've tried using a wrap_content on the RelativeLayout height and width. I've also played with scaleType as well as using a Scrollview. The problem with the ScrollView is that the image is both taller and wider than the display port (again this is meant to happen).
How can I make this work?
could it be that android:background scales the image to the screensize? try to use android:src instead.
Try this:
<ImageView
android:layout_height="fill_parent"
android:layout_width="fill_parent"
android:src="#drawable/postagram_blank_large"
android:scaleType="matrix"
/>
wrap_content instead of fill_parent also works, use whatever you want
I'm trying to place an image that fills the width of the screen, has the height of the actual image (wrap_content) and sits at the very bottom of the Layout.
I've wrote the below code, but between the second ImageView (the one with drawable/user_board) and the very bottom of the screen, there is a small space. Why is this? I've tried setting padding and margins to 0dp, but it seems it doesn't do the trick. Any ideas?
Here is the code:
<?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="fill_parent"
android:id="#+id/LayoutBoard"
android:noHistory="true"
android:padding="0dp" >
<ImageView
android:src="#drawable/game_interface_background"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:scaleType="matrix" />
<ImageView
android:src="#drawable/user_board"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_margin="0dp"
android:padding="0dp" />
</RelativeLayout>
Doesn't your user_board image have some transparent space at the bottom? Or maybe you can try setting negative value in the padding field of the second ImageView.
Use android:scaleType="fitXY" and the bitmap contained in your ImageView will be resized to fit the whole ImageView. So using this attribute in both your imageViews will probably hide that empty space. However keep in mind that this does not keep the aspect ratio of the image. See here for more information about the android:scaleType attribute tag and the possible values it can take.
I am trying to add ImageView programatically inside a LinearLayout, which has vertical orientation. My layout file is describe as the xml below:
<?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"
android:paddingTop="5dip"
android:id="#+id/mainView"">
<TextView android:id="#+id/tvTituloInformacao"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:textSize="20sp"
android:textStyle="bold"
android:textColor="#color/white"
android:gravity="center_horizontal"
android:shadowColor="#color/black_translucent"
android:shadowDx="2.0"
android:shadowDy="2.0"
android:shadowRadius="3.0"
android:layout_alignParentTop="true"
android:layout_alignParentLeft="true" />
<LinearLayout android:id="#+id/resourceContainer"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_marginTop="5dip"
android:layout_marginLeft="10dip"
android:layout_marginRight="10dip"
android:layout_marginBottom="10dip"
android:padding="3dip"
android:orientation="vertical"
android:gravity="center_horizontal"
android:layout_below="#+id/tvTituloInformacao"
android:background="#color/black_translucent2" />
</RelativeLayout>
And my java source code that adds the ImageViews to the LinearLayout is as follow:
for(Resource r : mUser.getPictures()) {
ImageView img = new ImageView(this);
img.setVisibility(View.VISIBLE);
img.setTag(r.getThumb60());
imageLoader.DisplayImage(r.getThumb60(), this, img);
((LinearLayout) tempFotosView.findViewById(R.id.resourceContainer)).addView(img);
}
What happens is that before and after each ImageView I am getting some extra spaces that should not be there, so the height of the images container increases a lot. One test that I did and got the expected result was not to use the imageLoader and instead I set the ImageResource programatically to a static image file. This way I didn't get any extra space.
The weird result is illustrated in the image below:
Is there a way to not add this extra space?
I think images you are loading in image views may have some extra spacing on top and bottom, and other assumption you are loading images in imageview, with different resolution than your screen-size, and setting scaleType of ImageView to centerInside, if it is the case please try using following by fixing height of the image view as well, and set scaleType to fixXY.
This happens when the image is wider than the screen size after the ImageView has been built. Android shrinks the image's dimensions accordingly to aspect ratio, but doesn't remove the allocated space around it earlier.
For a cleaner fix, try this code after your imageLoader.
((LinearLayout)findViewById(R.id.resource)).add(img);
Please advice how to place an image as background for LinearLayout so this image would look as is, not stretched, titled or something.
Other solution is to define your image in a XML and refer to this XML on your background as explained here : Background Image Placement
Like that you can control your image (background) layout
Jojo's solution might work if the content of Linear layout is smaller than image height.
if i add two or edit text automatically the image starts stretching. if u still want to avoid and make the imageview at background use the below xml layout.
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<ImageButton android:id="#+id/imageButton1" android:src="#drawable/icon" android:layout_width="fill_parent" android:layout_height="fill_parent" android:background="#null"></ImageButton>
<Button android:text="Button" android:id="#+id/button1" android:layout_width="wrap_content" android:layout_height="100px"></Button>
</RelativeLayout>
Because only image button has the src options that remains constant to width and height of image.
make android height and width of LinearLayout into wrap_content using this code in .xml file
android:layout_height="wrap_content"
android:layout_width="wrap_content"
to set background to the image use code
android:background="#drawable/image"
Now place the image in the drawable file