Получилось сделать с помощью margin (поставил отрицательный отступ, картинка увеличилась, видим небольшую часть).
Но она некорректно перемещается. При перемещении вправо и вверх, картинка сжимается, пока не исчезнет, потом сразу восстанавливается до нормального размера (то есть картинка рисуется в видимой области ImageView). Когда перемещаешь 2 раз и далее в том же направлении все работает нормально (то есть перемещается без проблем).
Еще не изучил движения пальцем, поэтому делал кнопками.
Вот код:
Код: Выделить всё
public class MainActivity extends ActionBarActivity implements OnClickListener{
Button Up,Down,Left,Right;
ImageView Image;
RelativeLayout.LayoutParams lParamsTV;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.rlayout);
Up = (Button) findViewById(R.id.Up);
Down = (Button) findViewById(R.id.Down);
Left = (Button) findViewById(R.id.Left);
Right = (Button) findViewById(R.id.Right);
Up.setOnClickListener(this);
Down.setOnClickListener(this);
Left.setOnClickListener(this);
Right.setOnClickListener(this);
Image = (ImageView) findViewById(R.id.Image);
lParamsTV = (RelativeLayout.LayoutParams) Image.getLayoutParams();
}
@Override
public void onClick(View v) {
switch (v.getId()) {
case R.id.Up:
lParamsTV.bottomMargin += 30;
Image.requestLayout();
break;
case R.id.Down:
lParamsTV.topMargin += 30;
Image.requestLayout();
break;
case R.id.Left:
lParamsTV.rightMargin += 30;
Image.requestLayout();
break;
case R.id.Right:
lParamsTV.leftMargin += 30;
Image.requestLayout();
break;
default:
break;
}
}
}
Код: Выделить всё
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_height="match_parent"
android:layout_width="match_parent"
android:orientation="vertical"
android:id="@+id/container" >
<RelativeLayout
android:id="@+id/rl1"
android:layout_width="match_parent"
android:layout_height="wrap_content" >
<Button
android:id="@+id/Up"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:layout_centerHorizontal="true"
android:text="Up" />
<Button
android:id="@+id/Down"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@+id/Right"
android:layout_centerHorizontal="true"
android:text="Down" />
<Button
android:id="@+id/Left"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@+id/Up"
android:layout_toLeftOf="@+id/Down"
android:text="Left" />
<Button
android:id="@+id/Right"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@+id/Up"
android:layout_toRightOf="@+id/Down"
android:text="Right" />
</RelativeLayout>
<RelativeLayout
android:id="@+id/rl2"
android:layout_width="match_parent"
android:layout_height="match_parent" >
<ImageView
android:id="@+id/Image"
android:layout_width="3000dp"
android:layout_height="3000dp"
android:layout_alignParentLeft="true"
android:layout_alignParentTop="true"
android:layout_marginLeft="-1500dp"
android:layout_marginRight="-1500dp"
android:layout_marginTop="-1500dp"
android:layout_marginBottom="-1500dp"
android:src="@drawable/image1" />
</RelativeLayout>
</LinearLayout>