You are on page 1of 9

Fetalvero, John Vincent C.

IT11S2-A20
layout\activity_main.xml

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


<androidx.constraintlayout.widget.ConstraintLayout
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=".MainActivity">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
tools:context=".MainActivity" >

<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#fc2a08"
>

<ImageView
android:id="@+id/ivPreview"
android:layout_width="150dp"
android:layout_height="150dp"
android:layout_centerHorizontal="true"
android:layout_centerVertical="true"
android:contentDescription="@string/img_preview"
android:background="#FFF" />

</RelativeLayout>

<LinearLayout
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_marginTop="10dp"
android:layout_weight="1"
android:background="#fca908"
android:gravity="center">

<ImageView
android:id="@+id/iv_mudkip"
android:layout_width="139dp"
android:layout_height="210dp"
android:contentDescription="@string/img_torchic"
android:onClick="changeImage"
android:src="@drawable/mudkip" />

<ImageView
android:id="@+id/iv_torchic"
android:layout_width="135dp"
android:layout_height="198dp"
android:contentDescription="@string/img_mudkip"
android:onClick="changeImage"
android:src="@drawable/torchic" />

<ImageView
android:id="@+id/iv_treecko"
android:layout_width="133dp"
android:layout_height="199dp"
android:contentDescription="@string/img_treecko"
android:onClick="changeImage"
android:src="@drawable/treecko" />
</LinearLayout>
</LinearLayout>

</androidx.constraintlayout.widget.ConstraintLayout>

land\activity_main.xml

<LinearLayout 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"
android:orientation="horizontal"
android:baselineAligned="false"
tools:context=".MainActivity" >

<RelativeLayout
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:background="#fc2a08"
>

<ImageView
android:id="@+id/ivPreview"
android:layout_width="150dp"
android:layout_height="150dp"
android:layout_centerHorizontal="true"
android:layout_centerVertical="true"
android:contentDescription="@string/img_preview"
android:background="#FFF" />

</RelativeLayout>

<ScrollView
android:id="@+id/scrollView1"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1"
android:layout_marginLeft="10dp"
android:background="#fca908"
>

<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center"
android:orientation="vertical" >

<ImageView
android:id="@+id/iv_mudkip"
android:layout_width="139dp"
android:layout_height="210dp"
android:contentDescription="@string/img_torchic"
android:onClick="changeImage"
android:src="@drawable/mudkip" />
<ImageView
android:id="@+id/iv_torchic"
android:layout_width="135dp"
android:layout_height="198dp"
android:contentDescription="@string/img_mudkip"
android:onClick="changeImage"
android:src="@drawable/torchic" />

<ImageView
android:id="@+id/iv_treecko"
android:layout_width="133dp"
android:layout_height="199dp"
android:contentDescription="@string/img_treecko"
android:onClick="changeImage"
android:src="@drawable/treecko" />
</LinearLayout>
</ScrollView>
</LinearLayout>
MainActivity.java

package com.example.androidappthree;

import androidx.appcompat.app.AppCompatActivity;

import android.os.Bundle;
import android.view.View;
import android.widget.ImageView;
import android.app.Activity;

public class MainActivity extends AppCompatActivity {


ImageView ivPreview;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
ivPreview = (ImageView) findViewById(R.id.ivPreview);
}
public void changeImage(View v){
switch(v.getId()){
case R.id.iv_torchic:
ivPreview.setBackgroundResource(R.drawable.torchic);
break;
case R.id.iv_mudkip:
ivPreview.setBackgroundResource(R.drawable.mudkip);
break;
case R.id.iv_treecko:
ivPreview.setBackgroundResource(R.drawable.treecko);
break;
}
}
}

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

<string name="app_name">AndroidAppThree</string>
<string name="action_settings">Settings</string>
<string name="img_preview">Image Preview</string>
<string name="img_mudkip">mudkip</string>
<string name="img_torchic">torchic</string>
<string name="img_treecko">treecko</string>

</resources>

You might also like