Hello! I am beginner ina android programming, although I started making new app for school. All is good, but there is one problem. How to make when I zoom I can move picture from right to left and from up to down and see all picture. Run my code and you will understand, what I mean.
public class MainActivity extends Activity{
Spinner spin;
TextView tw;
String[] states;
ImageView image;
TypedArray imgs;
ZoomControls zoom;
RelativeLayout rl;
@override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE);
zoom = (ZoomControls) findViewById(R.id.zoomControls);
states = getResources().getStringArray(R.array.klassid);
imgs = getResources().obtainTypedArray(R.array.pildid);
image = (ImageView) findViewById(R.id.imageView);
spin = (Spinner) findViewById(R.id.spinner);
Button b= (Button)findViewById(R.id.button);
rl = (RelativeLayout)findViewById(R.id.RelativeLayout);
image.getLayoutParams().width = 660;
image.getLayoutParams().height = 450;
b.setOnClickListener(new View.OnClickListener(){
public void onClick(View v) {
Intent i = new Intent(Intent.ACTION_VIEW, Uri.parse("https://johvi.ope.ee/auth/"));
startActivity(i);
}
});
//zoomControls
zoom.setOnZoomInClickListener(new View.OnClickListener() {
@TargetApi(Build.VERSION_CODES.JELLY_BEAN)
@override
public void onClick(View v) {
// TODO Auto-generated method stub
float x = image.getScaleX();
float y = image.getScaleY();
image.setScaleX(x + 1);
image.setScaleY(y + 1);
tw.setText("lol");
}
});
zoom.setOnZoomOutClickListener(new View.OnClickListener() {
@override
public void onClick(View v) {
// TODO Auto-generated method stub
float x = image.getScaleX();
float y = image.getScaleY();
image.setScaleX(x - 1);
image.setScaleY(y - 1);
}
});
ArrayAdapter<String> dataAdapter = new ArrayAdapter<String>(this,
android.R.layout.simple_spinner_item, states);
dataAdapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
spin.setAdapter(dataAdapter);
spin.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {
@override
public void onItemSelected(AdapterView<?> parent, View view,
int position, long id) {
image.setImageResource(imgs.getResourceId(
spin.getSelectedItemPosition(), -1));
}
@override
public void onNothingSelected(AdapterView<?> arg0) {
}
});
}
public boolean onCreateOptionsMenu(Menu menu) {
getMenuInflater().inflate(R.menu.menu_main, menu);
return true;
}
public class function implements AdapterView.OnItemSelectedListener {
@override
public void onItemSelected(AdapterView<?> parent, View view, int position, long id) {
String str = parent.getItemAtPosition(position).toString();
}
@override
public void onNothingSelected(AdapterView<?> parent) {
tw.setText("Valige klass");
}
}
}
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MainActivity"
android:id="@+id/RelativeLayout">
<TextView android:text="Valige klass" android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textColor="#ff06080a"
android:id="@+id/textView"
android:ellipsize="start"
android:elegantTextHeight="false"
android:textSize="20dp"
android:layout_alignParentTop="true"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true" />
<ScrollView
android:layout_width="100dp"
android:layout_height="100dp"
android:id="@+id/scrollView"
android:layout_above="@+id/button"
android:layout_toRightOf="@+id/textView"
android:layout_alignParentRight="true"
android:layout_alignParentEnd="true"
android:layout_below="@+id/textView">
<HorizontalScrollView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/horizontalScrollView" >
<FrameLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
>
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/imageView" />
</FrameLayout>
</HorizontalScrollView>
</ScrollView>
<Spinner
android:layout_width="100dp"
android:layout_height="100dp"
android:id="@+id/spinner"
android:entries="@array/klassid"
android:background="#00000000"
android:layout_below="@+id/textView"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:layout_marginTop="39dp" />
<Button
style="?android:attr/buttonStyleSmall"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Stuudium"
android:id="@+id/button"
android:background="#4e000000"
android:layout_alignParentBottom="true"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:layout_toLeftOf="@+id/scrollView"
android:layout_toStartOf="@+id/scrollView" />
<ZoomControls
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/zoomControls"
android:layout_alignParentBottom="true"
android:layout_alignParentRight="true"
android:layout_alignParentEnd="true" />
</RelativeLayout>
public class MainActivity extends Activity{
Spinner spin;
TextView tw;
String[] states;
ImageView image;
TypedArray imgs;
ZoomControls zoom;
RelativeLayout rl;
@override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE);
zoom = (ZoomControls) findViewById(R.id.zoomControls);
states = getResources().getStringArray(R.array.klassid);
imgs = getResources().obtainTypedArray(R.array.pildid);
image = (ImageView) findViewById(R.id.imageView);
spin = (Spinner) findViewById(R.id.spinner);
Button b= (Button)findViewById(R.id.button);
rl = (RelativeLayout)findViewById(R.id.RelativeLayout);
image.getLayoutParams().width = 660;
image.getLayoutParams().height = 450;
b.setOnClickListener(new View.OnClickListener(){
public void onClick(View v) {
Intent i = new Intent(Intent.ACTION_VIEW, Uri.parse("https://johvi.ope.ee/auth/"));
startActivity(i);
}
});
//zoomControls
zoom.setOnZoomInClickListener(new View.OnClickListener() {
@TargetApi(Build.VERSION_CODES.JELLY_BEAN)
@override
public void onClick(View v) {
// TODO Auto-generated method stub
float x = image.getScaleX();
float y = image.getScaleY();
image.setScaleX(x + 1);
image.setScaleY(y + 1);
tw.setText("lol");
}
});
zoom.setOnZoomOutClickListener(new View.OnClickListener() {
@override
public void onClick(View v) {
// TODO Auto-generated method stub
float x = image.getScaleX();
float y = image.getScaleY();
image.setScaleX(x - 1);
image.setScaleY(y - 1);
}
});
ArrayAdapter<String> dataAdapter = new ArrayAdapter<String>(this,
android.R.layout.simple_spinner_item, states);
dataAdapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
spin.setAdapter(dataAdapter);
spin.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {
@override
public void onItemSelected(AdapterView<?> parent, View view,
int position, long id) {
image.setImageResource(imgs.getResourceId(
spin.getSelectedItemPosition(), -1));
}
@override
public void onNothingSelected(AdapterView<?> arg0) {
}
});
}
public boolean onCreateOptionsMenu(Menu menu) {
getMenuInflater().inflate(R.menu.menu_main, menu);
return true;
}
public class function implements AdapterView.OnItemSelectedListener {
@override
public void onItemSelected(AdapterView<?> parent, View view, int position, long id) {
String str = parent.getItemAtPosition(position).toString();
}
@override
public void onNothingSelected(AdapterView<?> parent) {
tw.setText("Valige klass");
}
}
}
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MainActivity"
android:id="@+id/RelativeLayout">
<TextView android:text="Valige klass" android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textColor="#ff06080a"
android:id="@+id/textView"
android:ellipsize="start"
android:elegantTextHeight="false"
android:textSize="20dp"
android:layout_alignParentTop="true"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true" />
<ScrollView
android:layout_width="100dp"
android:layout_height="100dp"
android:id="@+id/scrollView"
android:layout_above="@+id/button"
android:layout_toRightOf="@+id/textView"
android:layout_alignParentRight="true"
android:layout_alignParentEnd="true"
android:layout_below="@+id/textView">
<HorizontalScrollView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/horizontalScrollView" >
<FrameLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
>
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/imageView" />
</FrameLayout>
</HorizontalScrollView>
</ScrollView>
<Spinner
android:layout_width="100dp"
android:layout_height="100dp"
android:id="@+id/spinner"
android:entries="@array/klassid"
android:background="#00000000"
android:layout_below="@+id/textView"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:layout_marginTop="39dp" />
<Button
style="?android:attr/buttonStyleSmall"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Stuudium"
android:id="@+id/button"
android:background="#4e000000"
android:layout_alignParentBottom="true"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:layout_toLeftOf="@+id/scrollView"
android:layout_toStartOf="@+id/scrollView" />
<ZoomControls
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/zoomControls"
android:layout_alignParentBottom="true"
android:layout_alignParentRight="true"
android:layout_alignParentEnd="true" />
</RelativeLayout>