메인화면
<?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"
tools:context=".MainActivity">
<androidx.constraintlayout.widget.ConstraintLayout
android:layout_margin="16dp"
android:layout_width="match_parent"
android:layout_height="80dp">
<de.hdodenhof.circleimageview.CircleImageView
android:id="@+id/my_profile"
android:layout_width="80dp"
android:layout_height="match_parent"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintBottom_toBottomOf="parent"
android:src="@drawable/thumb_moana"
/>
<TextView
android:id="@+id/title"
android:text="Moana"
android:textColor="#838383"
android:textSize="18sp"
android:textStyle="bold"
android:layout_width="150dp"
android:layout_height="40dp"
app:layout_constraintLeft_toRightOf="@+id/my_profile"
app:layout_constraintTop_toTopOf="parent"
android:padding="8dp"
android:layout_marginLeft="20dp"/>
<TextView
android:id="@+id/sub_title"
android:text="Hello. How are you today?"
android:textColor="#838383"
android:textSize="15sp"
android:layout_width="150dp"
android:layout_height="40dp"
app:layout_constraintLeft_toRightOf="@+id/my_profile"
app:layout_constraintTop_toBottomOf="@+id/title"
android:padding="8dp"
android:layout_marginLeft="20dp"/>
<TextView
android:id="@+id/profile_day"
android:text="2022.08.26"
android:textColor="#838383"
android:textSize="15sp"
android:layout_width="150dp"
android:layout_height="40dp"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintRight_toRightOf="parent"
android:gravity="right"
android:paddingTop="15dp"
android:paddingRight="8dp"/>
</androidx.constraintlayout.widget.ConstraintLayout>
<HorizontalScrollView
android:layout_width="match_parent"
android:layout_height="80dp"
android:padding="5dp"
android:orientation="horizontal"
android:scrollbars="none">
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="match_parent">
<de.hdodenhof.circleimageview.CircleImageView
android:layout_width="50dp"
android:layout_height="match_parent"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintBottom_toBottomOf="parent"
android:layout_marginRight="8dp"
android:src="@drawable/moana01"
app:civ_border_width="1dp"
/>
<de.hdodenhof.circleimageview.CircleImageView
android:layout_width="50dp"
android:layout_height="match_parent"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintBottom_toBottomOf="parent"
android:layout_marginRight="8dp"
android:src="@drawable/moana01"
app:civ_border_width="1dp"
/>
<de.hdodenhof.circleimageview.CircleImageView
android:layout_width="50dp"
android:layout_height="match_parent"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintBottom_toBottomOf="parent"
android:layout_marginRight="8dp"
android:src="@drawable/moana01"
app:civ_border_width="1dp"
/>
<de.hdodenhof.circleimageview.CircleImageView
android:layout_width="50dp"
android:layout_height="match_parent"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintBottom_toBottomOf="parent"
android:layout_marginRight="8dp"
android:src="@drawable/moana01"
app:civ_border_width="1dp"
/>
<de.hdodenhof.circleimageview.CircleImageView
android:layout_width="50dp"
android:layout_height="match_parent"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintBottom_toBottomOf="parent"
android:layout_marginRight="8dp"
android:src="@drawable/moana01"
app:civ_border_width="1dp"
/>
<de.hdodenhof.circleimageview.CircleImageView
android:layout_width="50dp"
android:layout_height="match_parent"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintBottom_toBottomOf="parent"
android:layout_marginRight="8dp"
android:src="@drawable/moana01"
app:civ_border_width="1dp"
/>
<de.hdodenhof.circleimageview.CircleImageView
android:layout_width="50dp"
android:layout_height="match_parent"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintBottom_toBottomOf="parent"
android:layout_marginRight="8dp"
android:src="@drawable/moana01"
app:civ_border_width="1dp"
/>
<de.hdodenhof.circleimageview.CircleImageView
android:layout_width="50dp"
android:layout_height="match_parent"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintBottom_toBottomOf="parent"
android:layout_marginRight="8dp"
android:src="@drawable/moana01"
app:civ_border_width="1dp"
/>
<de.hdodenhof.circleimageview.CircleImageView
android:layout_width="50dp"
android:layout_height="match_parent"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintBottom_toBottomOf="parent"
android:layout_marginRight="8dp"
android:src="@drawable/moana01"
app:civ_border_width="1dp"
/>
</LinearLayout>
</HorizontalScrollView>
<TextView
android:layout_width="match_parent"
android:layout_height="1dp"
android:background="#838383"/>
<LinearLayout
android:layout_marginTop="8dp"
android:padding="10dp"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:weightSum="10">
<LinearLayout
android:layout_gravity="left"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:orientation="vertical"
android:layout_weight="9">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="androidprimeinfo"
android:textColor="@color/black"
android:textStyle="bold"
android:textSize="15sp"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Metro Manila, Philippines"
android:textColor="@color/black"
android:textSize="16sp"/>
</LinearLayout>
<ImageView
android:id="@+id/etc_img"
android:layout_width="0dp"
android:layout_height="30dp"
android:layout_weight="1"
android:layout_marginTop="5dp"
android:src="@drawable/baseline_more_vert_24"/>
</LinearLayout>
<ImageView
android:id="@+id/mainImg"
android:layout_width="match_parent"
android:layout_height="280dp"
android:scaleType="centerCrop"
android:src="@drawable/paris"/>
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="40dp"
android:layout_marginLeft="10dp"
android:layout_marginRight="10dp"
android:orientation="horizontal">
<ImageView
android:id="@+id/like_img"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_alignParentLeft="true"
android:src="@drawable/baseline_favorite_24"
/>
<ImageView
android:id="@+id/chat_img"
android:layout_marginLeft="13dp"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_toRightOf="@+id/like_img"
android:src="@drawable/baseline_chat_bubble_outline_24"
/>
<ImageView
android:id="@+id/send_img"
android:layout_marginLeft="13dp"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_toRightOf="@+id/chat_img"
android:src="@drawable/baseline_send_24"
/>
<ImageView
android:id="@+id/down_img"
android:layout_marginLeft="8dp"
android:layout_width="wrap_content"
android:padding="5dp"
android:layout_height="match_parent"
android:layout_alignParentRight="true"
android:src="@drawable/baseline_move_to_inbox_24"
/>
<TextView
android:layout_width="match_parent"
android:layout_height="1dp"
android:background="#AAAAAA"
android:layout_alignParentBottom="true"/>
</RelativeLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:layout_margin="10dp"
>
<TextView
android:layout_width="match_parent"
android:layout_height="18dp"
android:text="Write your description here..."
android:textColor="@color/black"
android:textStyle="bold"/>
<TextView
android:layout_marginTop="10dp"
android:layout_width="match_parent"
android:layout_height="25dp"
android:text="26 MINUTES AGO"
android:textColor="#A5A5A5"
android:textSize="10sp"
/>
</LinearLayout>
</LinearLayout>
내가 만든 팝업
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="200dp"
android:layout_height="wrap_content"
android:orientation="vertical">
<ImageView
android:id="@+id/dialog_img"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:adjustViewBounds="true"
android:baselineAligned="false"
android:src="@drawable/sydney" />
<ImageView
android:id="@+id/dialog_btn"
android:layout_width="match_parent"
android:layout_height="13dp"
android:layout_margin="5dp"
android:src="@drawable/baseline_circle_24" />
</LinearLayout>
자바소스
package com.bsj0420.tp06tostanddialog;
import androidx.appcompat.app.AppCompatActivity;
import android.app.AlertDialog;
import android.media.Image;
import android.os.Bundle;
import android.view.View;
import android.widget.ImageView;
import android.widget.Toast;
public class MainActivity extends AppCompatActivity {
ImageView sliderImg, mainImg, etcImg, likeImg, chatImg, sendImg, downImg;
ImageView dialogImg, dialogBtn;
int[] imgArrMain = {R.drawable.moana01, R.drawable.moana02, R.drawable.moana03};
int[] imgArr = {R.drawable.newyork, R.drawable.paris, R.drawable.sydney};
int num = 0;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
etcImg = findViewById(R.id.etc_img);
likeImg = findViewById(R.id.like_img);
chatImg = findViewById(R.id.chat_img);
sendImg = findViewById(R.id.send_img);
downImg = findViewById(R.id.down_img);
etcImg.setOnClickListener(listener);
likeImg.setOnClickListener(listener);
chatImg.setOnClickListener(listener);
sendImg.setOnClickListener(listener);
downImg.setOnClickListener(listener);
mainImg = findViewById(R.id.mainImg);
mainImg.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
AlertDialog.Builder builder = new AlertDialog.Builder(MainActivity.this);
builder.setView(R.layout.img_big);
AlertDialog dialog = builder.create();
dialog.setCanceledOnTouchOutside(false);
dialog.show();
dialogImg = dialog.findViewById(R.id.dialog_img);
dialogImg.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
dialogImg.setImageResource(imgArr[0 + num]);
num ++;
if(num > 2) num=0;
}
});
dialogBtn = dialog.findViewById(R.id.dialog_btn);
dialogBtn.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
dialog.dismiss();
}
});
}
});
}
View.OnClickListener listener = new View.OnClickListener() {
@Override
public void onClick(View view) {
int id = view.getId();
if(id == R.id.etc_img) MakeToast("더보기");
else if(id == R.id.like_img) MakeToast("좋아요");
else if(id == R.id.chat_img) MakeToast("메세지");
else if(id == R.id.send_img) MakeToast("보내기");
else if(id == R.id.down_img) MakeToast("저장");
}
};
void MakeToast(String s){
Toast.makeText(MainActivity.this,s, Toast.LENGTH_SHORT).show();
}
}