0% found this document useful (0 votes)
32 views3 pages

Rapport Arknoid

The document describes an Android activity layout and its corresponding MainActivity class. The layout contains multiple ImageViews arranged in a relative layout. The MainActivity class handles touch input for some of the ImageViews. When the tank ImageView is dragged, it is moved horizontally. When the ball ImageView is tapped, it is animated up and out of view. The activity also conditions visibility of other ImageViews based on the ball's vertical position.

Uploaded by

omar
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
32 views3 pages

Rapport Arknoid

The document describes an Android activity layout and its corresponding MainActivity class. The layout contains multiple ImageViews arranged in a relative layout. The MainActivity class handles touch input for some of the ImageViews. When the tank ImageView is dragged, it is moved horizontally. When the ball ImageView is tapped, it is animated up and out of view. The activity also conditions visibility of other ImageViews based on the ball's vertical position.

Uploaded by

omar
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 3

activity

<?xml version="1.0" encoding="utf-8"?>


<RelativeLayout xmlns:android="http://schemas.android.com/apk/
res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context="com.example.mac.test_arknoid.MainActivity"
android:background="@color/colorPrimaryDark">

<ImageView
android:id="@+id/imageView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:layout_marginBottom="16dp"
android:layout_marginLeft="113dp"
android:layout_marginStart="113dp"
app:srcCompat="@drawable/tank" />

<ImageView
android:id="@+id/imageView3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
app:srcCompat="@drawable/liste1"
android:layout_alignTop="@+id/imageView3"
android:layout_centerHorizontal="true" />

<ImageView
android:id="@+id/imageView4"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignBottom="@+id/imageView"
android:layout_alignEnd="@+id/imageView"
android:layout_alignRight="@+id/imageView"
app:srcCompat="@drawable/ball" />

<ImageView
android:id="@+id/imageView6"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_above="@+id/imageView4"
android:layout_alignEnd="@+id/imageView3"
android:layout_alignRight="@+id/imageView3"
app:srcCompat="@drawable/boto" />

<ImageView
android:id="@+id/imageView7"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignLeft="@+id/imageView3"
android:layout_alignParentTop="true"
android:layout_alignStart="@+id/imageView3"
app:srcCompat="@drawable/liste2" />

</RelativeLayout>

MainActivity
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.MotionEvent;
import android.view.View;
import android.widget.ImageView;

public class MainActivity extends AppCompatActivity implements


View.OnTouchListener {
ImageView iv,iv2,iv3,iv4,iv5;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
iv=(ImageView) findViewById(R.id.imageView);
iv2=(ImageView) findViewById(R.id.imageView4);
iv3=(ImageView) findViewById(R.id.imageView3);
iv4=(ImageView) findViewById(R.id.imageView6);
iv5=(ImageView) findViewById(R.id.imageView7);

iv5.setVisibility(View.INVISIBLE);
iv.setOnTouchListener(this);
iv4.setOnTouchListener(this);

}
float x = 0.0f;
int k=0;
@Override
public boolean onTouch(View arg0, MotionEvent arg1) {
if(arg0==iv){
if (arg1.getAction() == MotionEvent.ACTION_MOVE) {

x = arg1.getRawX() -iv.getHeight() ;
iv.setX(x);

}
if(iv2.getY()<150){
iv3.setVisibility(View.INVISIBLE);
iv5.setVisibility(View.VISIBLE);

}
}
if(arg0==iv4){
if (arg1.getAction() == MotionEvent.ACTION_DOWN) {

iv2.animate().translationY(-1400).setDuration(2500);

}}

return true;
}
}

You might also like