Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7073361
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T05:55:13+00:00 2026-05-28T05:55:13+00:00

I have a image and blank linear layout , when i drag button linear

  • 0

I have a image and blank linear layout , when i drag button linear layout also move . I need to drag and drop button on linear layout and linear layout should be fixed position .

My Android XML :-

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical" >

<ScrollView
    android:id="@+id/scrollViewRequestDriver"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:fillViewport="true"
    android:scrollbars="horizontal" >

    <LinearLayout
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        android:orientation="vertical"
        android:paddingLeft="10dip"
        android:paddingRight="10dip" >

        <LinearLayout
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:orientation="horizontal" >

            <LinearLayout
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:orientation="vertical" >

                <ImageView
                    android:id="@+id/ballItem"
                    android:layout_width="50sp"
                    android:layout_height="50sp"
                    android:src="@drawable/icon" >
                </ImageView>
            </LinearLayout>

            <LinearLayout
                android:id="@+id/linearlayoutItem"
                android:layout_width="fill_parent"
                android:layout_height="200dp"
                android:background="#ffffff"
                android:gravity="center"                   
                android:orientation="vertical" >
            </LinearLayout>
        </LinearLayout>

        <ListView
            android:id="@+id/lvItems"
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:divider="#FFFFFF"
            android:dividerHeight="2dip" >
        </ListView>

        <Button
            android:id="@+id/btnAdd"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:onClick="btnAdd_Click"
            android:text="Add New Item" >
        </Button>
    </LinearLayout>
</ScrollView>

</LinearLayout>

My Code is :-

package com.beanie.example;


import java.util.ArrayList;
import java.util.List;

import com.beanie.example.BusinessObjects.Item;
import com.beanie.example.provider.ItemAdapter;
import com.beanie.example.BusinessManager.ItemManager;

import android.app.Activity;
import android.app.ProgressDialog;
import android.content.Context;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.os.AsyncTask;
import android.os.Bundle;
import android.os.Handler;
import android.util.Log;
import android.view.KeyEvent;
import android.view.MotionEvent;
import android.view.View;
import android.view.View.OnFocusChangeListener;
import android.view.View.OnKeyListener;
import android.view.View.OnTouchListener;
import android.view.ViewGroup.OnHierarchyChangeListener;
import android.view.animation.AlphaAnimation;
import android.view.animation.Animation;
import android.widget.EditText;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.ListView;
import android.widget.LinearLayout.LayoutParams;

public class Dashboard extends Activity implements OnTouchListener {
int windowwidth;
int windowheight;
private ItemAdapter ia;
Context context=null;
List<Item> items = null;
ProgressDialog signInProgress = null;
public Handler h = new Handler();
private LinearLayout linearlayout1;
private LayoutParams layoutParams ;
private LayoutParams layoutParams1 ;
int x_cord;
int y_cord;

@Override
protected void onCreate(Bundle savedInstanceState) {
    // TODO Auto-generated method stub
    super.onCreate(savedInstanceState);
    setContentView(R.layout.dashboard);


    windowwidth = getWindowManager().getDefaultDisplay().getWidth();
    windowheight = getWindowManager().getDefaultDisplay().getHeight();

    ImageView ball= (ImageView)findViewById(R.id.ballItem);
    ball.setOnTouchListener(this);

    linearlayout1= (LinearLayout)findViewById(R.id.linearlayoutItem);   


}   


public boolean onTouch(View v, MotionEvent event) {
    switch(v.getId())
    {
    case R.id.ballItem:
        ImageView ball= (ImageView)findViewById(R.id.ballItem);
        layoutParams = (LayoutParams) ball.getLayoutParams();
        switch(event.getAction())
        {
        case MotionEvent.ACTION_DOWN:               
            ball.setAlpha(255);
            break;

        case MotionEvent.ACTION_MOVE:
             x_cord = (int)event.getRawX();
             y_cord = (int)event.getRawY();

            if(x_cord>windowwidth){x_cord=windowwidth;}
            if(y_cord>windowheight){y_cord=windowheight;}
            x_cord= x_cord -25;
            y_cord=y_cord - 230;
            layoutParams.leftMargin = x_cord ;
            layoutParams.topMargin = y_cord ;
            ball.setAlpha(45);
            ball.setLayoutParams(layoutParams);
            break;          
        case MotionEvent.ACTION_UP:             

            layoutParams.leftMargin = x_cord ;
            layoutParams.topMargin = y_cord;

            ImageView ball1= new ImageView(context);
            Animation animation = new AlphaAnimation(0.0f, 1.0f);
            animation.setDuration(5000);
            Bitmap bm = BitmapFactory.decodeResource(getResources(), R.drawable.icon);
            ball1.setImageBitmap(bm);
            ball1.setAnimation(animation);          
            ball1.setLayoutParams(layoutParams);
            linearlayout1.addView(ball1);
            animation=null;

            EditText tv= new EditText(context);
            tv.setWidth(200);
            tv.setHint("TextBox 1");


            linearlayout1.addView(tv);
            EditText tv1= new EditText(context);
            tv1.setWidth(200);
            tv1.setHint("TextBox 2");


            //slide from top and bottom
            AnimUtils.setLayoutAnim_slidedownfromtop(linearlayout1, context);

            layoutParams.leftMargin = 0;
            layoutParams.topMargin =  0;
            ball.setAlpha(255);
            ball.setLayoutParams(layoutParams);

            break;
        default : break;
        }            

    }
    return true;
}


}

Please suggest me usable link or modification in my code .

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-28T05:55:14+00:00Added an answer on May 28, 2026 at 5:55 am

    Please check the below threads ,There are some good example for drag and drop a view :

    http://techdroid.kbeanie.com/2010/04/simple-drag-n-drop-on-android.html

    http://blahti.wordpress.com/2011/01/17/moving-views-part-2/

    Thanks

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a layout with two ImageView inside. Each image has a fixed aspect
I have a layout, with a image, button and a textview. When I set
I have image map that can I move, but this map will be so
I decided to move my Android project to C++, and I have a problem.
I have this layout: <LinearLayout android:layout_width=fill_parent android:layout_height=wrap_content android:layout_marginBottom=10dp android:gravity=center_vertical android:layout_marginLeft=10dp> <CheckBox android:id=@+id/screen_login_checkbox android:button=@drawable/login_screen_checkbox_image_selector android:layout_width=wrap_content
I'm going to set image perspective. I have image of laptop with blank polygon
I have a layout like this: <ScrollView android:id=@+id/ScrollViewHome android:layout_width=fill_parent android:layout_height=fill_parent android:background=#ffffff android:fillViewport=true > <LinearLayout
I have a custom spinner layout with an image and a text view but
I have a LinearLayout layout with a ListView in it. I've made the android:background
I have a problem with changing button background image. So i have 2 images

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.