안드로이드

 

 

 

 

 

 

 

 

 

class MainActivity
package org.androidtown.myframelayout;

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

public class MainActivity extends AppCompatActivity {

    ImageView imageView, imageView2;

    boolean selected=false;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        imageView =(ImageView)findViewById(R.id.imageView);
        imageView2 =(ImageView)findViewById(R.id.imageView2);

        Button button=(Button)findViewById(R.id.button);

        button.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {

                if(selected){
                    imageView.setVisibility(View.VISIBLE);
                    imageView2.setVisibility(View.GONE);
                }else{
                    imageView.setVisibility(View.GONE);
                    imageView2.setVisibility(View.VISIBLE);
                }

                selected = !selected;
            }
        });

    }


}

 

 

R.layout.activity_main
<?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:id="@+id/activity_main"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:paddingBottom="@dimen/activity_vertical_margin"
    android:paddingLeft="@dimen/activity_horizontal_margin"
    android:paddingRight="@dimen/activity_horizontal_margin"
    android:paddingTop="@dimen/activity_vertical_margin"
    tools:context="org.androidtown.myframelayout.MainActivity">

    <FrameLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:layout_below="@+id/button">

        <ImageView
            android:layout_width="match_parent"
            app:srcCompat="@drawable/a1"
            android:id="@+id/imageView"
            android:layout_height="200dp" />

        <ImageView
            android:layout_width="match_parent"
            app:srcCompat="@drawable/a2"
            android:id="@+id/imageView2"
            android:layout_height="200dp" />
    </FrameLayout>

    <Button
        android:text="Button"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:id="@+id/button"
        android:layout_alignParentTop="true"
        android:layout_centerHorizontal="true" />
</RelativeLayout>

 

 

 

 

 

android

 

about author

PHRASE

Level 60  머나먼나라

시작이 반이라 , 무슨 일이든지 시작하기가 어렵지, 일단 손을 대면 반 이상은 한 것이나 다름이 없다는 말.

댓글 ( 4)

댓글 남기기

작성