728x90

# 실행 화면

# activity1.xml

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
	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"
    android:orientation="vertical"
    android:layout_margin="10dp"
    tools:context=".Activity1">

    <LinearLayout
        android:id="@+id/linearLayout1"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:scaleType="centerInside"
        android:background="@drawable/border">

        <ImageButton
        android:id="@+id/imageButton1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_weight="1"
        android:adjustViewBounds="true"
        android:scaleType="fitXY"
        android:padding="0dp"
        android:layout_margin="5dp"
        android:src="@drawable/picture1"
        android:onClick="onClick"/>

        <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:orientation="vertical"
            android:layout_weight="2"
            android:layout_margin="3dp">

            <TextView
                android:id="@+id/title1"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:text="Starry Night" />

            <TextView
                android:id="@+id/name1"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:text="고흐" />
        </LinearLayout>
    </LinearLayout>

    <LinearLayout
        android:id="@+id/linearLayout2"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:scaleType="centerInside"
        android:background="@drawable/border">

        <ImageButton
            android:id="@+id/imageButton2"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_weight="1"
            android:adjustViewBounds="true"
            android:scaleType="fitXY"
            android:padding="0dp"
            android:layout_margin="5dp"
            android:src="@drawable/picture2"
            android:onClick="onClick"/>

        <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:orientation="vertical"
            android:layout_weight="2"
            android:layout_margin="3dp">

            <TextView
                android:id="@+id/title2"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:text="Still Life with Kettle" />

            <TextView
                android:id="@+id/name2"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:text="폴 세잔" />
        </LinearLayout>
    </LinearLayout>
</LinearLayout>

# border.xml

<?xml version="1.0" encoding="utf-8"?>
<shape 
	xmlns:android="http://schemas.android.com/apk/res/android"
    android:padding="10dp"
    android:shape="rectangle" >
    <solid android:color="#F4F3E7" />
    <corners
        android:bottomLeftRadius="12dp"
        android:bottomRightRadius="12dp"
        android:topLeftRadius="12dp"
        android:topRightRadius="12dp" />
    <stroke
        android:width="1dp"
        android:color="#000" />
</shape>

# activity2.xml

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
    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"
    android:orientation="vertical">

    <TextView
        android:id="@+id/title"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:gravity="center"
        android:textColor="#430404"
        android:background="@drawable/gradation"/>

    <TextView
        android:id="@+id/name"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_margin="10dp"
        android:background="#1705FF75"
        android:layout_gravity="right"
        android:textColor="#06810B" />

    <ImageView
        android:id="@+id/imageView"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:scaleType="fitStart" />
</LinearLayout>

# gradation.xml

<?xml version="1.0" encoding="utf-8"?>
<shape 
	xmlns:android="http://schemas.android.com/apk/res/android"
    android:shape="rectangle">
    <gradient
        android:angle="0"
        android:type="linear"
        android:startColor="#FDF2E1"
        android:centerColor="#F8E6B1"
        android:endColor="#FDF2E1"/>
</shape>

# Activity1.java

package kr.ac.skuniv.intenttest1;

import androidx.appcompat.app.AppCompatActivity;
import android.content.Intent;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.os.Bundle;
import android.view.View;
import android.widget.ImageButton;
import android.widget.TextView;
import java.io.ByteArrayOutputStream;

public class Activity1 extends AppCompatActivity {
    ImageButton imageButton1, imageButton2;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity1);
        setTitle("2018305065_명화 목록");
        imageButton1 = (ImageButton) findViewById(R.id.imageButton1);
        imageButton2 = (ImageButton) findViewById(R.id.imageButton2);
    }
    public void onClick(View view){
        Intent intent = new Intent(Activity1.this, Activity2.class);
        switch(view.getId()){
            case R.id.imageButton1:
                TextView title1 = ((TextView) findViewById(R.id.title1));
                TextView name1 = ((TextView) findViewById(R.id.name1));
                intent.putExtra("title", title1.getText().toString());
                intent.putExtra("name", name1.getText().toString());

                Bitmap bitmap1 = BitmapFactory.decodeResource(getResources(), R.drawable.picture1);
                ByteArrayOutputStream stream1 = new ByteArrayOutputStream();
                bitmap1.compress(Bitmap.CompressFormat.JPEG, 100, stream1);
                byte[] byteArray1 = stream1.toByteArray();
                intent.putExtra("image", byteArray1);

                startActivity(intent);
                break;

            case R.id.imageButton2:
                TextView title2 = ((TextView) findViewById(R.id.title2));
                TextView name2 = ((TextView) findViewById(R.id.name2));
                intent.putExtra("title", title2.getText().toString());
                intent.putExtra("name", name2.getText().toString());

                Bitmap bitmap2 = BitmapFactory.decodeResource(getResources(), R.drawable.picture2);
                ByteArrayOutputStream stream2 = new ByteArrayOutputStream();
                bitmap2.compress(Bitmap.CompressFormat.JPEG, 100, stream2);
                byte[] byteArray2 = stream2.toByteArray();
                intent.putExtra("image", byteArray2);

                startActivity(intent);
                break;
        }
    }
}

# Activity2.java

package kr.ac.skuniv.intenttest1;

import androidx.appcompat.app.AppCompatActivity;
import android.content.Intent;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.os.Bundle;
import android.widget.ImageView;
import android.widget.TextView;

public class Activity2 extends AppCompatActivity {
    TextView textView1, textView2;
    ImageView imageView;
    @Override
    protected void onCreate(Bundle savedInstancedState){
        super.onCreate(savedInstancedState);
        setContentView(R.layout.activity2);
        setTitle("명화");
        textView1 = (TextView) findViewById(R.id.title);
        textView2 = (TextView) findViewById(R.id.name);
        imageView = (ImageView) findViewById(R.id.imageView);

        Intent intent = getIntent();
        String title = intent.getStringExtra("title");
        String name = intent.getStringExtra("name");
        byte[] byteArray = getIntent().getByteArrayExtra("image");
        Bitmap image = BitmapFactory.decodeByteArray(byteArray, 0, byteArray.length);

        textView1.setText(title);
        textView2.setText(name);
        imageView.setImageBitmap(image);
    }
}
반응형
  • 네이버 블러그 공유하기
  • 네이버 밴드에 공유하기
  • 페이스북 공유하기
  • 카카오스토리 공유하기