728x90
반응형
1. 갤러리뷰(Gallery)
1) 사진이나 이미지를 배치하고 좌우로 스크롤해서 볼 수 있도록 해줌
2) 이미지 목록을 스크롤하는 기능만 존재
3) 좀 더 부드럽고, 고급스러운 느낌을 줌
<?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="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical"
tools:context=".MainActivity">
<Gallery
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="@+id/gallery"
android:spacing="5dp"/>
<ImageView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="@+id/ivPoster"
android:padding="20dp"/>
</LinearLayout>
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="horizontal"
android:gravity="center"
android:background="#00FF00"
android:layout_width="match_parent"
android:layout_height="match_parent">
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/imageView1"
android:src="@drawable/movie_icon"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@id/textView"
android:text="TextView"/>
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/imageView11"
android:src="@drawable/movie_icon"/>
</LinearLayout>
package kr.co.galleryapp;
import androidx.appcompat.app.AppCompatActivity;
import android.content.Context;
import android.os.Bundle;
import android.view.MotionEvent;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.Gallery;
import android.widget.ImageView;
import android.widget.TextView;
import android.widget.Toast;
public class MainActivity extends AppCompatActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
getSupportActionBar().setDisplayShowHomeEnabled(true);
getSupportActionBar().setIcon(R.drawable.ic_launcher);
setTitle("갤러리 영화(업그레이드)");
Gallery gallery = findViewById(R.id.gallery);
MyGalleryAdapter galleryAdapter = new MyGalleryAdapter(this);
gallery.setAdapter(galleryAdapter);
}
private class MyGalleryAdapter extends BaseAdapter {
Context context;
Integer[] posterID = {
R.drawable.mov01, R.drawable.mov02, R.drawable.mov03, R.drawable.mov04, R.drawable.mov05,
R.drawable.mov06, R.drawable.mov07, R.drawable.mov08, R.drawable.mov09, R.drawable.mov10,
R.drawable.mov11, R.drawable.mov12, R.drawable.mov13, R.drawable.mov14, R.drawable.mov15,
R.drawable.mov16, R.drawable.mov17, R.drawable.mov18, R.drawable.mov19, R.drawable.mov20,
R.drawable.mov21, R.drawable.mov22, R.drawable.mov23, R.drawable.mov24, R.drawable.mov25,
R.drawable.mov26, R.drawable.mov27, R.drawable.mov28, R.drawable.mov29, R.drawable.mov30,
R.drawable.mov31, R.drawable.mov32, R.drawable.mov33, R.drawable.mov34, R.drawable.mov35,
R.drawable.mov36, R.drawable.mov37, R.drawable.mov38, R.drawable.mov39, R.drawable.mov40,
R.drawable.mov41, R.drawable.mov42, R.drawable.mov43, R.drawable.mov44, R.drawable.mov45,
R.drawable.mov46, R.drawable.mov47, R.drawable.mov48, R.drawable.mov49, R.drawable.mov50,
R.drawable.mov51, R.drawable.mov52, R.drawable.mov53, R.drawable.mov54, R.drawable.mov55,
R.drawable.mov56, R.drawable.mov57, R.drawable.mov58, R.drawable.mov59, R.drawable.mov60,
R.drawable.mov61, R.drawable.mov62, R.drawable.mov63, R.drawable.mov64, R.drawable.mov65,
R.drawable.mov66, R.drawable.mov67, R.drawable.mov68, R.drawable.mov69, R.drawable.mov70,
R.drawable.mov71, R.drawable.mov72, R.drawable.mov73, R.drawable.mov74, R.drawable.mov75,
R.drawable.mov76, R.drawable.mov77, R.drawable.mov78, R.drawable.mov79, R.drawable.mov80,
R.drawable.mov81, R.drawable.mov82, R.drawable.mov83 };
String[] posterTitle = { "토이스토리1", "호빗2", "제이슨 본3", "반지의 왕4", "정직한 후보5",
"토이스토리6", "호빗7", "제이슨 본8", "반지의 왕9", "정직한 후보10",
"토이스토리11", "호빗12", "제이슨 본13", "반지의 왕14", "정직한 후보15",
"토이스토리16", "호빗17", "제이슨 본18", "반지의 왕19", "정직한 후보20",
"토이스토리21", "호빗22", "제이슨 본23", "반지의 왕24", "정직한 후보25",
"토이스토리26", "호빗27", "제이슨 본28", "반지의 왕29", "정직한 후보30",
"토이스토리31", "호빗32", "제이슨 본33", "반지의 왕34", "정직한 후보35",
"토이스토리36", "호빗37", "제이슨 본38", "반지의 왕39", "정직한 후보40",
"토이스토리41", "호빗42", "제이슨 본43", "반지의 왕44", "정직한 후보45",
"토이스토리46", "호빗47", "제이슨 본48", "반지의 왕49", "정직한 후보50",
"토이스토리51", "호빗52", "제이슨 본53", "반지의 왕54", "정직한 후보55",
"토이스토리56", "호빗57", "제이슨 본58", "반지의 왕59", "정직한 후보60",
"토이스토리61", "호빗62", "제이슨 본63", "반지의 왕64", "정직한 후보65",
"토이스토리66", "호빗67", "제이슨 본68", "반지의 왕69", "정직한 후보70",
"토이스토리71", "호빗72", "제이슨 본73", "반지의 왕74", "정직한 후보75",
"토이스토리76", "호빗77", "제이슨 본78", "반지의 왕79", "정직한 후보80",
"토이스토리81", "호빗82", "제이슨 본83"};
public MyGalleryAdapter(Context context){
this.context = context;
}
@Override
public int getCount() {
return posterID.length;
}
@Override
public Object getItem(int i) {
return null;
}
@Override
public long getItemId(int i) {
return 0;
}
@Override
public View getView(int i, View view, ViewGroup viewGroup) {
ImageView imageView = new ImageView(context);
imageView.setLayoutParams(new Gallery.LayoutParams(200, 300));
imageView.setScaleType(ImageView.ScaleType.FIT_CENTER);
imageView.setPadding(5,5,5,5);
imageView.setImageResource(posterID[i]);
final int pos = i;
imageView.setOnTouchListener(new View.OnTouchListener() {
@Override
public boolean onTouch(View view, MotionEvent motionEvent) {
ImageView ivPoster = findViewById(R.id.ivPoster);
ivPoster.setScaleType(ImageView.ScaleType.FIT_CENTER);
ivPoster.setImageResource(posterID[pos]);
Toast toast = new Toast(getApplicationContext());
View toastView = View.inflate(getApplicationContext(), R.layout.toast, null);
TextView toastText = toastView.findViewById(R.id.textView);
toastText.setText(posterTitle[pos]);
toast.setView(toastView);
toast.show();
return false;
}
});
return imageView;
}
}
}
[결과 출력]
728x90
반응형
'App > Android Java' 카테고리의 다른 글
Android_Java(28) - AudioPlay (0) | 2022.02.15 |
---|---|
Android_Java(27) - SGM (0) | 2022.02.14 |
Android_Java(25) - MyGridView (0) | 2022.02.14 |
Android_Java(24) - MovieCustomListView(2) (0) | 2022.02.14 |
Android_Java(23) - MovieCustomListView (0) | 2022.02.13 |
댓글