1. Download our Official Android App: Forums for Android!

Apps image overlay

Discussion in 'Android Development' started by bermaneyal, Aug 7, 2011.

  1. bermaneyal

    bermaneyal Lurker
    Thread Starter
    Rank:
    None
    Points:
    5
    Posts:
    2
    Joined:
    Aug 7, 2011

    Aug 7, 2011
    2
    0
    5
    Hi,

    I trying to implement a image as background and put images on top of it.
    this is my layout.
    Code (Text):
    1. <FrameLayout android:id="@+id/my_ph" xmlns:android="http://schemas.android.com/apk/res/android"
    2.     android:layout_width="wrap_content"
    3.     android:layout_height="wrap_content">
    4. <ImageView  
    5.     android:id="@+id/image"
    6.     android:layout_width="wrap_content"
    7.     android:layout_height="wrap_content"
    8.     android:src="@drawable/sketch" />
    9. </FrameLayout>
    and my class
    Code (Text):
    1. import android.app.Activity;
    2. import android.os.Bundle;
    3. import android.view.View.OnClickListener;
    4. import android.widget.FrameLayout;
    5. import android.widget.ImageButton;
    6. import android.widget.Toast;
    7.  
    8. public class myActivity extends Activity {
    9.     /** Called when the activity is first created. */
    10.     @Override
    11.     public void onCreate(Bundle savedInstanceState) {
    12.         super.onCreate(savedInstanceState);
    13.         setContentView(R.layout.main);
    14.        
    15.         FrameLayout rv =(FrameLayout)findViewById(R.id.my_ph);
    16.        
    17.         ImageButton im1 = new ImageButton(this);
    18.         im1.setBackgroundResource(R.drawable.lamp_off_x);
    19.         im1.setMinimumHeight(50);
    20.         im1.setMinimumWidth(50);
    21.         im1.setOnClickListener(OnLampClickListener());
    22.         im1.layout(50,50, 0, 0);
    23.        
    24.         rv.addView(im1);
    25.      }
    26.    
    27.     OnClickListener OnLampClickListener(){
    28.       Toast.makeText(getBaseContext(), "Lamp",Toast.LENGTH_LONG);
    29.       return null;
    30.     }
    31. }
    my questions:
    1. how to put the images im1 in specific place(x,y) on top of my ImageView.
    2. how to implement the click event on the image im1 (i will have more images like that)
    3. if i will dynamic load images on my ImageView how to know which image i clicked (where and how to save the image id that came from db).

    Eyal
     

    Advertisement

  2. dimiter

    dimiter Newbie
    Rank:
    None
    Points:
    16
    Posts:
    27
    Joined:
    Jul 27, 2011

    Jul 27, 2011
    27
    3
    16
    Moscow
    1)Use absolute layout Learn Android: Absolute layout . You can put view on absolute layout so:
    Code (Text):
    1.  
    2. AbsoluteLayout.LayoutParams params=new AbsoluteLayout.LayoutParams(
    3.                         width, height, x, y
    4. );
    5. mView.setLayoutParams(params);
    6. AbsLay.addView(mView)
    7.  
    It layout is deprecated, because in some screens your app will poor like - sizes and coordinates already same. But if you add views in code, you can calculate coordinates and sizes - depending screen params:
    Code (Text):
    1.  
    2. protected void GetScreenSize(){
    3.         Display display = getWindowManager().getDefaultDisplay();
    4.         screen_x = display.getWidth();
    5.         screen_y = display.getHeight();
    6.  }
    7.  
    2 and 3)Create ImageView array and assign id to every image. Next setOnClickListener(this) on every image and parse image id in click listener code.
     
  3. bermaneyal

    bermaneyal Lurker
    Thread Starter
    Rank:
    None
    Points:
    5
    Posts:
    2
    Joined:
    Aug 7, 2011

    Aug 7, 2011
    2
    0
    5
    1) i want to use deprecated layouts
    2,3) the event isn't working i click on the image but nothing appand.
     

Share This Page

Loading...