While i touch and move the size of View is changing.But my requirement is only change the size without change the position of top left.
Here is the xml_code alert_window.xml
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/rl_main"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="@drawable/musiq_bg" >
<RelativeLayout
android:id="@+id/r1"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_marginTop="10dip"
android:layout_marginLeft="10dp"
android:layout_marginRight="10dp" >
<RelativeLayout
android:id="@+id/liner"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_below="@+id/ll" >
<TextView
android:id="@+id/edit_list_name2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:layout_marginTop="5dip"
android:gravity="center"
android:text="--- -"
android:textAppearance="?android:attr/textAppearanceSmall" />
<ScrollView
android:id="@+id/scroll"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_above="@+id/liner2"
android:layout_below="@+id/edit_list_name2">
<RelativeLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content">
<TextView
android:id="@+id/defualt_button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:ellipsize="end"
android:layout_marginLeft="2dip"
android:layout_marginRight="2dip"
android:layout_marginTop="2dp"
android:layout_marginBottom="1dp"
android:text="Smack that all on the floor \nSmack that give me some more\n"
android:textAppearance="?android:attr/textAppearanceSmall"/>
</RelativeLayout>
</ScrollView>
<RelativeLayout
android:id="@+id/liner2"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_marginTop="2dp" >
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_centerVertical="true"
android:padding="3dp" />
<ImageView
android:id="@+id/iv_expand"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:src="@drawable/popup_expand"
android:layout_centerVertical="true"
android:padding="3dp"/>
</RelativeLayout>
</RelativeLayout>
</RelativeLayout>
</RelativeLayout>
Here is the class
public class ResizeService extends Service {
ImageView iv_expand;
int height_layout,width,height,height_params;
WindowManager windowManager;
View myView;
@Override
public IBinder onBind(Intent intent) {
// Not used
return null;
}
@SuppressLint("NewApi")
@Override
public void onCreate() {
super.onCreate();
//470,420 wrap content,500
windowManager = (WindowManager) getSystemService(WINDOW_SERVICE);
DisplayMetrics metrics = ResizeService.this.getResources().getDisplayMetrics();
width = metrics.widthPixels;
height = metrics.heightPixels;
width=(width/100)*100;
height_params=(height/100)*40;
//window for the main layout
final WindowManager.LayoutParams params = new winndowManager.LayoutParams(width,height_params, WindowManager.LayoutParams.TYPE_PHONE, WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE, PixelFormat.TRANSLUCENT);
params.gravity = Gravity.TOP | Gravity.LEFT;
LayoutInflater inflater = (LayoutInflater) getSystemService(LAYOUT_INFLATER_SERVICE);
myView = inflater.inflate(R.layout.alert_window, null);
iv_expand = (ImageView) myView.findViewById(R.id.iv_expand);
windowManager.addView(myView, params);
iv_expand.setOnTouchListener(new OnTouchListener() {
private int initial_expand_X;
private int initial_expand_Y;
private float initialExpandTouchX;
private float initialExpandTouchY;
@Override
public boolean onTouch(View v, MotionEvent event) {
try {
switch (event.getAction()) {
case MotionEvent.ACTION_DOWN:
initial_expand_X = params.x;
initial_expand_Y = params.y;
initialExpandTouchX = event.getRawX();
initialExpandTouchY = event.getRawY();
return true;
case MotionEvent.ACTION_UP:
return true;
case MotionEvent.ACTION_MOVE:
params.x = initial_expand_X + (int) (event.getRawX() - initialExpandTouchX);
params.y = initial_expand_Y + (int) (event.getRawY() - initialExpandTouchY);
params.width=(int) event.getRawX();
params.height=(int)event.getRawY();
windowManager.updateViewLayout(myView, params);
return true;
}
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
return false;
}
});
}
}