2
안드로이드의 레이아웃 내부에 여러 이미지를 집어 넣을 수있는 사람을 도와 줄 수 있습니까?이 코드에서 경계 제한으로 드래그를 완료했습니다. 이제 이미지를 확대하고 싶습니다. 나는 경계 한계안드로이드에서 집게 확대/축소를 구현하는 방법
TouchActivity extends Activity{
/** Called when the activity is first created. */
ImageView robot=null,bird=null;
AbsoluteLayout aLayout,aLayout1;
int status=0,status1=0;
// We can be in one of these 3 states
static final int NONE = 0;
static final int DRAG = 1;
static final int ZOOM = 2;
int mode = NONE;
int displayHeight, displayWidth;
Matrix matrix = new Matrix();
Matrix savedMatrix = new Matrix();
Matrix matrixForView1 = new Matrix();
Matrix matrixForView2 = new Matrix();
PointF start = new PointF();
PointF mid = new PointF();
float oldDist = 1f;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
aLayout= (AbsoluteLayout)findViewById(R.id.absLayout);
DisplayMetrics metrics = new DisplayMetrics();
getWindowManager().getDefaultDisplay().getMetrics(metrics);
displayHeight = metrics.heightPixels;
displayWidth = metrics.widthPixels;
robot=(ImageView)findViewById(R.id.robot);
bird=(ImageView)findViewById(R.id.bird);
bird.setOnTouchListener(new OnTouchListener() {
@Override
public boolean onTouch(View v, MotionEvent event) {
status1=1;
Log.i("Touched BIRD ImageStatus1",""+status1);
//robot.setBackgroundColor(Color.WHITE);
return false;
}
});
robot.setOnTouchListener(new OnTouchListener() {
@Override
public boolean onTouch(View v, MotionEvent event) {
status=1;
Log.i("Touched ROBOT ImageStatus",""+status);
//robot.setBackgroundColor(Color.WHITE);
return false;
}
});
aLayout.setOnTouchListener(new OnTouchListener() {
@Override
public boolean onTouch(View v, MotionEvent event) {
// TODO Auto-generated method stub
Log.i("touch",""+event);
LayoutParams lp;
if((event.getX()>0&&event.getX()<320)&&(event.getY()>0 && event.getY()<480))
{
if(status==1) // any event from down and move
{
lp = new LayoutParams(LayoutParams.WRAP_CONTENT,LayoutParams.WRAP_CONTENT,(int)event.getX()-robot.getWidth()/2,(int)event.getY()-robot.getHeight()/2);
robot.setLayoutParams(lp);
}
if(status1==1) // any event from down and move
{
Log.e("event.getX()", String.valueOf(event.getX()));
Log.e("event.getY()", String.valueOf(event.getY()));
lp = new LayoutParams(LayoutParams.WRAP_CONTENT,LayoutParams.WRAP_CONTENT,(int)event.getX()-bird.getWidth()/2,(int)event.getY()-bird.getHeight()/2);
bird.setLayoutParams(lp);
}
}
else
{
Log.e("image outside boundary","image outside boundary");
}
if(event.getAction()==MotionEvent.ACTION_UP){
if(status==1)
{
status=0;
robot.setBackgroundColor(Color.TRANSPARENT);
}
if(status1==1)
{ status1=0;
bird.setBackgroundColor(Color.TRANSPARENT);
}
}
return true;
}
});
}
}
여러 이미지를 드래그 여기 내 코드를 공유하고이 내 레이아웃
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/LLayout"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical" >
<AbsoluteLayout
android:id="@+id/absLayout"
android:layout_width="fill_parent"
android:layout_height="fill_parent" >
<ImageView
android:id="@+id/robot"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@drawable/ic_launcher"
android:scaleType="matrix"
/>
<ImageView
android:id="@+id/bird"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@drawable/white_bird"
android:scaleType="matrix"
android:layout_x="200dp"
/>
</AbsoluteLayout>
</LinearLayout>
이다가이 코드에서 그것을 할 수 있습니까? 행렬 방법이 나를 위해 속임수가됩니까?
미리 감사드립니다.
그것은 내가 HTML에서 얻을 anything.The 값이 난 레이아웃에서 아무것도 설정
.Should 것을 보여 나던? – playmaker420죄송합니다 ... 파일 경로가/mnt/sdarcd /로 시작하고 file : // – Shrikant
으로 시작하지 않아 문제가 해결 되었습니까? – Shrikant