This question already has an answer here:
这个问题在这里已有答案:
- How can I get zoom functionality for images? 13 answers
- 如何获得图像的缩放功能? 13个答案
This is my code below which crete layout programically. How do i set zoom in and zoom out programicallly when click on image? I want my program to react when user click on image is enlarge full screen and when click again is go resume original size what do i do?
这是我的代码,下面以编程方式进行克里特岛布局。单击图像时如何设置放大和缩小程序?我希望我的程序在用户点击图像放大全屏时做出反应,当再次点击是恢复原始大小我该怎么办?
final DatabaseConnector dbConnector = new DatabaseConnector(this);
dbConnector.open();
Cursor cursor =
dbConnector.getStageRequirements(Long.valueOf(currentStageID).longValue());
reqdata = new MyData1[cursor.getCount()];
int j = cursor.getCount();
cursor.moveToFirst();
i = 0;
while (cursor.isAfterLast() == false)
{
reqdata[i] = new MyData1(cursor.getString(1), cursor.getString(0));
cursor.moveToNext();
i++;
}
dbConnector.close();
cursor.close();
ScrollView scroll = new ScrollView(MainActivity1.this);
scroll.setLayoutParams(new
LinearLayout.LayoutParams(LayoutParams.WRAP_CONTENT,
LayoutParams.WRAP_CONTENT));
btnLO = new LinearLayout(MainActivity1.this);
LinearLayout.LayoutParams paramsLO = new
LinearLayout.LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT);
// button margins
paramsLO.setMargins(0, 0, 0, 0);
LinearLayout.LayoutParams paramsLO2 = new
LinearLayout.LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT);
// button margins
paramsLO2.setMargins(0, 20, 0, 0);
// button height/width *pixels*
btnLO.setOrientation(LinearLayout.VERTICAL);
btnLO.setBackgroundColor(5); // not working correctly
//buttons
for (i =0;i <reqdata.length;i++)
{
LinearLayout li=new LinearLayout(this);
li.setOrientation(LinearLayout.HORIZONTAL);
final Button b1 = new Button(MainActivity1.this);
final ImageView imageView = new ImageView(MainActivity1.this);
int width = 60;
int height = 150;
LinearLayout.LayoutParams parms = new
LinearLayout.LayoutParams(width,height);
parms.setMargins(0, 5, 0, 0);
imageView.setLayoutParams(parms);
li.addView(b1, paramsLO);
li.addView(imageView);
btnLO.addView(li);
b1.setText(reqdata[i].getSpinnerText());
b1.setOnClickListener(new View.OnClickListener()
{
public void onClick(View v)
{
imageView1 = imageView;
Intent pictureActionIntent = new
Intent(MediaStore.ACTION_IMAGE_CAPTURE);
pictureActionIntent.putExtra(MediaStore.EXTRA_OUTPUT, Uri.fromFile(new
File(SDCARD_ROOT_PATH + SAVE_PATH_IN_SDCARD,IMAGE_CAPTURE_NAME)));
startActivityForResult(pictureActionIntent,CAMERA_PICTURE);
b1.setClickable(false);
}
});
}
final Button b2 = new Button(MainActivity1.this);
b2.setText("Submit");
b2.setWidth(150);
b2.setHeight(50);
b2.setOnClickListener(new View.OnClickListener()
{
public void onClick(View v)
{
long visitID = dbConnector.saveVisit();
for (i =0;i <reqdata.length;i++)
{
dbConnector.saveVisitDetail(listByte.get(i),visitID,Long.valueOf(reqdata[i].getValue()).longValue());
}
Toast.makeText(getBaseContext(), "Sucessful",Toast.LENGTH_SHORT).show();
Intent intent = new Intent(MainActivity1.this, Main.class);
startActivity(intent);
finish();
}
});
btnLO.addView(b2, paramsLO2);
btnLO.setGravity(Gravity.CENTER| Gravity.CENTER_HORIZONTAL);
scroll.addView(btnLO);
this.addContentView(scroll, new LayoutParams());
}
1 个解决方案
#1
0
Like Lalit Poptani said in another answer,
就像Lalit Poptani在另一个回答中所说的那样,
There is a nice running answer for this question on *. Please have a look at this, PinchZoom
*上有一个很好的运行答案。请看看PinchZoom
#1
0
Like Lalit Poptani said in another answer,
就像Lalit Poptani在另一个回答中所说的那样,
There is a nice running answer for this question on *. Please have a look at this, PinchZoom
*上有一个很好的运行答案。请看看PinchZoom