안드로이드 개발 질문/답변
(글 수 45,052)
public class GalleryDemoB1 extends Activity {
View mPage1, mPage2, mPage3;
Integer[] images = { R.drawable.pic1, R.drawable.pic2, R.drawable.pic3,
R.drawable.pic4, R.drawable.pic5, R.drawable.pic6 };
View mPage1, mPage2, mPage3;
Integer[] images = { R.drawable.pic1, R.drawable.pic2, R.drawable.pic3,
R.drawable.pic4, R.drawable.pic5, R.drawable.pic6 };
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
mPage1 = findViewById(R.id.page1);
mPage2 = findViewById(R.id.page2);
mPage3 = findViewById(R.id.page3);
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
mPage1 = findViewById(R.id.page1);
mPage2 = findViewById(R.id.page2);
mPage3 = findViewById(R.id.page3);
findViewById(R.id.btnpage1).setOnClickListener(mClickListener);
findViewById(R.id.btnpage2).setOnClickListener(mClickListener);
findViewById(R.id.btnpage3).setOnClickListener(mClickListener);
Gallery gallery = (Gallery) findViewById(R.id.gallery1);
findViewById(R.id.btnpage2).setOnClickListener(mClickListener);
findViewById(R.id.btnpage3).setOnClickListener(mClickListener);
Gallery gallery = (Gallery) findViewById(R.id.gallery1);
gallery.setAdapter(new ImageAdapter(this));
gallery.setOnItemClickListener(new OnItemClickListener() {
public void onItemClick(AdapterView parent, View v, int position,
long id) {
ImageView imageView = (ImageView) findViewById(R.id.image1);
imageView.setScaleType(ImageView.ScaleType.FIT_CENTER);
imageView.setImageResource(images[position]);
}
});
}
Button.OnClickListener mClickListener = new Button.OnClickListener() {
public void onClick(View v) {
mPage1.setVisibility(View.INVISIBLE);
mPage2.setVisibility(View.INVISIBLE);
mPage3.setVisibility(View.INVISIBLE);
switch (v.getId()) {
case R.id.btnpage1:
mPage1.setVisibility(View.VISIBLE);
break;
case R.id.btnpage2:
mPage2.setVisibility(View.VISIBLE);
break;
case R.id.btnpage3:
mPage3.setVisibility(View.VISIBLE);
break;
}
}
};
gallery.setOnItemClickListener(new OnItemClickListener() {
public void onItemClick(AdapterView parent, View v, int position,
long id) {
ImageView imageView = (ImageView) findViewById(R.id.image1);
imageView.setScaleType(ImageView.ScaleType.FIT_CENTER);
imageView.setImageResource(images[position]);
}
});
}
Button.OnClickListener mClickListener = new Button.OnClickListener() {
public void onClick(View v) {
mPage1.setVisibility(View.INVISIBLE);
mPage2.setVisibility(View.INVISIBLE);
mPage3.setVisibility(View.INVISIBLE);
switch (v.getId()) {
case R.id.btnpage1:
mPage1.setVisibility(View.VISIBLE);
break;
case R.id.btnpage2:
mPage2.setVisibility(View.VISIBLE);
break;
case R.id.btnpage3:
mPage3.setVisibility(View.VISIBLE);
break;
}
}
};
public class ImageAdapter extends BaseAdapter {
private Context context;
private int itemBackground;
public ImageAdapter(Context c) {
context = c;
TypedArray a = obtainStyledAttributes(R.styleable.Gallery1);
itemBackground = a.getResourceId(
R.styleable.Gallery1_android_galleryItemBackground, 0);
a.recycle();
}
R.styleable.Gallery1_android_galleryItemBackground, 0);
a.recycle();
}
public int getCount() {
return images.length;
}
public Integer getItem(int position) {
return images[position];
}
public long getItemId(int position) {
return position;
}
public View getView(int position, View convertView, ViewGroup parent) {
ImageView imageView = new ImageView(context);
imageView.setImageResource(getItem(position));
imageView.setLayoutParams(new Gallery.LayoutParams(100, 80));
imageView.setBackgroundResource(itemBackground);
return imageView;
}
}
}
return images.length;
}
public Integer getItem(int position) {
return images[position];
}
public long getItemId(int position) {
return position;
}
public View getView(int position, View convertView, ViewGroup parent) {
ImageView imageView = new ImageView(context);
imageView.setImageResource(getItem(position));
imageView.setLayoutParams(new Gallery.LayoutParams(100, 80));
imageView.setBackgroundResource(itemBackground);
return imageView;
}
}
}
xml문서
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent" xmlns:android="http://schemas.android.com/apk/res/android">
<LinearLayout android:id="@+id/linearLayout1" android:layout_height="wrap_content" android:layout_width="fill_parent" android:orientation="horizontal">
<Button android:layout_height="wrap_content" android:layout_width="wrap_content" android:id="@+id/btnpage1" android:text="기본소개"></Button>
<Button android:layout_height="wrap_content" android:layout_width="wrap_content" android:id="@+id/btnpage2" android:text="행사별소개"></Button>
<Button android:layout_height="wrap_content" android:layout_width="wrap_content" android:id="@+id/btnpage3" android:text="교통편"></Button>
<FrameLayout
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="@drawable/ass"
>
<LinearLayout
android:id="@+id/page1"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="@drawable/ass"
>
<TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:textColor="#000000"
android:layout_marginTop="15px"
android:text="몸짓의 향연 춘천마임축제 CHUNCHEON"
<LinearLayout android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent" xmlns:android="http://schemas.android.com/apk/res/android">
<LinearLayout android:id="@+id/linearLayout1" android:layout_height="wrap_content" android:layout_width="fill_parent" android:orientation="horizontal">
<Button android:layout_height="wrap_content" android:layout_width="wrap_content" android:id="@+id/btnpage1" android:text="기본소개"></Button>
<Button android:layout_height="wrap_content" android:layout_width="wrap_content" android:id="@+id/btnpage2" android:text="행사별소개"></Button>
<Button android:layout_height="wrap_content" android:layout_width="wrap_content" android:id="@+id/btnpage3" android:text="교통편"></Button>
<FrameLayout
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="@drawable/ass"
>
<LinearLayout
android:id="@+id/page1"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="@drawable/ass"
>
<TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:textColor="#000000"
android:layout_marginTop="15px"
android:text="몸짓의 향연 춘천마임축제 CHUNCHEON"
android:textSize="6pt"
/> .....
이렇게 만들었는데 버튼을 이미지 사이 가운데 검은색 부분에 넣을려면 어떻게 해야 하나요? 저 작은 사진과 큰사진이 모두 이미지 뷰에 속해서 레이아웃을 따로 만들어야 하나요? 그리고 버튼이 클릭되면 큰사진 있는곳에 내용을
보여 주려고 하는데 위에처럼 버튼 옆에 뜨네요. 어떻게 바꿔줘야하나요??