Best way to add dragable images onto another image in android - android

I was wondering what the best way to add dragable images to another image is in android. For example if I had an image of someones face how could I add an smaller image of say a comedy mouth and drag it into the correct position on the original image. Is there a nice way to go about this?
Thanks in advance

You can use FrameLayout to overlap your images.Check this out:
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<ImageView
android:id="#+id/imageView1"
android:src="#drawable/img_face"
android:scaleType="fitCenter"
android:layout_height="250px"
android:layout_width="250px"/>
<ImageView
android:id="#+id/imageView2"
android:layout_height="fill_parent"
android:layout_width="fill_parent"
android:src="#drawable/comedy_face"
android:gravity="center"/>
</FrameLayout>

Related

Android - Place image in relativeLayout with proper size

I am working on a android card view. Here is the code that I have now:
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="wrap_content" >
<RelativeLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_margin="10dip"
android:orientation="vertical"
android:background="#drawable/drawable_card_bg">
<ImageView
android:id="#+id/photo"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:src="#drawable/test_img" />
....
and the UI looks like:
However this is not what I am looking for. I want the image to be placed on top of the card, with the top, right, left margins to be 10dip from the background card boarder.
Meanwhile, I want to keep the ratio of the image, so don't want to hard-code the width/height of the image view. I want the image width to fit the width of the background card, and the height should be adjusted according to the width.
How should I change the layout parameters to achieve this?
Thank you
Add android:adjustViewBounds="true" to your ImageView in xml in order to let the ImageView adjust its bounds.
It's very easy......... please do this thing. Replace your imageview code using this one
<ImageView
android:id="#+id/photo"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:scaleType="fitXY"
android:adjustViewBounds="true"
android:src="#drawable/test_img" />
If my answer will help you then support this.
Thanks!!!

Gallery view with circular effect to both edges

I am working on application in which gallery require as bellow image :
I searched over internet but it gives result similar to Image Gallery. But I want to create the gallery which will move in circular fashion, means it just bend the first and last member of gallery. Is it possible? or Is the horizontal ScrollView better approach to do this?
Any better approach will be appreciated.. Thanks in advance.
I have found a solution and it achieved using Custom Gallery. I used following layout file for that
main.xml
<?xml version="1.0" encoding="utf-8"?>
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/linear_layout"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:background="#drawable/gal_bg"
android:orientation="vertical" >
<Gallery
android:id="#+id/horizontallistview"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="40dp"
android:layout_marginRight="40dp" />
<!-- android:background="#drawable/gal_overlay" -->
<ImageView
android:layout_width="fill_parent"
android:layout_height="120dp"
android:background="#drawable/gal_overlay" />
</FrameLayout>
And it uses the some images as background to FrameLayout and ImageView. You will find the complete source code of project on GitHub.
Happy Coding..

How to arrange images inside Relative Layout

I am just starting with Android and cannot find a way to arrange the images the way I want.
This is what I am looking for:
This is the code I am currently using, to arrange the images, which unfortunately does not work.
<RelativeLayout
android:layout_width="wrap_content"
android:layout_height="0dp"
android:layout_weight="1.5"
android:orientation="horizontal"
android:layout_gravity="center">
<ImageView
android:id="#+id/imageView1"
android:layout_width="240dp"
android:layout_height="240dp"
android:src="#drawable/delicio"/>
<ImageView
android:id="#+id/imageView2"
android:layout_width="240dp"
android:layout_height="240dp"
android:src="#drawable/logoerrado"/>
</RelativeLayout>
How can I arrange the images how I want?
To get image1 in the upper right hand corner, use
android:layout_alignParentTop="true"
android:layout_alignParentRight="true"
To get image 2 in the center horizontally, use android:layout_centerHorizontal="true". Then add enough padding via android:paddingTop to get it down as far as you want.
If you want another layout beneath image2, like I see in your drawing, just put android:layout_below="#+id/img2" to it.

How to create layout with android's different display size

My problem born when i create layout in xml file from graphics tool. RelativeLayout is awful! i don't know which layout to use.. When i put an imageview and a imagebutton, in emulator will displayed in a bad way, one apon the other. what can i do? is there a good tutorial on which i can learn how to resize image and layout in percent of different displays size?
i Try this :
<RelativeLayout android:layout_width="match_parent" android:id="#+id/relativeLayout1" android:layout_height="match_parent">
<LinearLayout android:layout_width="wrap_content" android:id="#+id/linearLayout1" android:orientation="vertical" android:layout_height="wrap_content" android:layout_alignParentTop="true" android:layout_alignParentLeft="true">
<ImageView android:id="#+id/imageView1" android:src="#drawable/testotrova" android:layout_width="243dp" android:layout_height="48dp"></ImageView>
</LinearLayout>
<ImageButton android:layout_width="wrap_content" android:src="#drawable/info" android:layout_height="wrap_content" android:id="#+id/imageButton1" android:layout_alignParentTop="true" android:layout_alignParentRight="true"></ImageButton>
</RelativeLayout>
but when i display it isn't good
Regarding support for multiple screens, have a look here.
You will need to add different layouts for screen size small, normal and large.
They are displayed one upon the other because you are using RelativeLayour and they are both (Image and text) anchored to the upper left:
android:layout_alignParentTop="true" android:layout_alignParentLeft="true"
I strongly suggest you to use LinearLayout if you have only a few items. (http://www.learn-android.com/2010/01/05/android-layout-tutorial/4/)
For your image size, if you want a percent, please use:
android:layout_height="0dip"
android:layout_weight="1"
http://developer.android.com/resources/articles/layout-tricks-efficiency.html

Scrolling between views

I'm currently working on a game for android.
I have three ImageView's next to each other, they're positioned next to each other using the "android:layout_toRightOf". The views are located within a RelativeLayout tag. Each of these views are centered into the middle of the screen using "android:scaleType="fitCenter"" and they fill the entire screen.
I'm attempting to implement a horizontal scroll from one view to another so that I basically get one view on my screen at a time.
Here is the code that I'm currently using
<HorizontalScrollView android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:fillViewport="true"
android:scrollbars="none">
<RelativeLayout android:id="#+id/GameBg"
android:layout_width="wrap_content"
android:layout_height="wrap_content">
<ImageView android:id="#+id/GameImageContainer3"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:scaleType="fitCenter"
android:layout_toRightOf="#+id/GameImageContainer2"
/>
<ImageView android:id="#+id/GameImageContainer2"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:scaleType="fitCenter"
android:layout_toRightOf="#+id/GameImageContainer1"
/>
<ImageView android:id="#+id/GameImageContainer1"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:scaleType="fitCenter"
/>
</RelativeLayout>
</HorizontalScrollView>
What I'm currently getting is three images next to each other -- but sometimes they take up less then an entire screen. I want both the left and right padding to be correct, so that I can only see one image at a time.
Any ideas?
Have you tried the Gallery Widget. It seems to be what you are looking for. Be sure to also check out the Gallery tutorial.
Try using a ViewFlipper
http://www.androidpeople.com/android-viewflipper-example/

Categories

Resources