안드로이드 개발 질문/답변
(글 수 45,052)
실행 시키면
위에 갤러리 있고
아래 해당 웹뷰로 페이지 연결 되어서 뜨는 형식으로 만들어져 있습니다.
그런데요. 이걸 아예 갤러리가 중앙에 뜨고 갤러리 클릭 시 전체 화면이 웹뷰가 뜨게끔 만들려면
어떻게 만들어야 될까요??
바쁘신 와중에 신경 써주시고 들어와주셔서 감사합니다.
소스코드
package com.corea.Ch10Ex01_Gallery1;
소스코드
package com.corea.Ch10Ex01_Gallery1;
import android.app.Activity;
import android.content.Context;
import android.content.res.TypedArray;
import android.os.Bundle;
import android.view.View;
import android.view.ViewGroup;
import android.webkit.WebView;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemClickListener;
import android.widget.BaseAdapter;
import android.widget.Gallery;
import android.widget.ImageView;
import android.widget.Toast;
public class Ch10Ex01_Gallery1 extends Activity{
/** Called when the activity is first created. */
private Integer[] mGalleryIds = {
R.drawable.chrysanthemum, R.drawable.desert,
};
private String[] mGalleryDataIds = {
"Photo by Kim in 2001", "Photo by David in 2002",
};
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
final Gallery gallery = (Gallery)findViewById(R.id.gallery1);
gallery.setAdapter(new GalleryImageView(this));
gallery.setOnItemClickListener(new OnItemClickListener(){
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
Webpage(position);
Toast.makeText(Ch10Ex01_Gallery1.this, ""+"Phoro number"+position+"/"
+mGalleryDataIds[position], Toast.LENGTH_LONG).show();
}
});
}
public void Webpage(int a){
WebView browser;
browser =(WebView)findViewById(R.id.webview);
if(a == 1)
{
browser.loadUrl("file:///android_asset/htmlview.html");
}
}
public class GalleryImageView extends BaseAdapter {
int mGalleryItemBackground;
private Context mContext;
public GalleryImageView(Context c) {
mContext = c;
TypedArray ta = obtainStyledAttributes(R.styleable.Gallery1);
mGalleryItemBackground=ta.getResourceId(R.styleable.Gallery1_android_galleryItemBackground, 0);
ta.recycle();
}
public int getCount(){
return mGalleryIds.length;
}
public Object getItem(int position){
return null;
}
public long getItemId(int position) {
return 0;
}
public View getView(int position, View convertView, ViewGroup parent) {
ImageView imageView;
if(convertView == null){
imageView = new ImageView(mContext);
imageView.setLayoutParams(new Gallery.LayoutParams(150, 120));
imageView.setScaleType(ImageView.ScaleType.CENTER_CROP);
imageView.setBackgroundResource(mGalleryItemBackground);
}
else {
imageView = (ImageView) convertView;
}
imageView.setImageResource(mGalleryIds[position]);
return imageView;
}
}
}
메인.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
>
<Gallery
android:id="@+id/gallery1"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
/>
<WebView
android:id="@+id/webview"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
/>
</LinearLayout>
private String[] mGalleryDataIds = {
"Photo by Kim in 2001", "Photo by David in 2002",
};
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
final Gallery gallery = (Gallery)findViewById(R.id.gallery1);
gallery.setAdapter(new GalleryImageView(this));
gallery.setOnItemClickListener(new OnItemClickListener(){
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
Webpage(position);
Toast.makeText(Ch10Ex01_Gallery1.this, ""+"Phoro number"+position+"/"
+mGalleryDataIds[position], Toast.LENGTH_LONG).show();
}
});
}
public void Webpage(int a){
WebView browser;
browser =(WebView)findViewById(R.id.webview);
if(a == 1)
{
browser.loadUrl("file:///android_asset/htmlview.html");
}
}
public class GalleryImageView extends BaseAdapter {
int mGalleryItemBackground;
private Context mContext;
public GalleryImageView(Context c) {
mContext = c;
TypedArray ta = obtainStyledAttributes(R.styleable.Gallery1);
mGalleryItemBackground=ta.getResourceId(R.styleable.Gallery1_android_galleryItemBackground, 0);
ta.recycle();
}
public int getCount(){
return mGalleryIds.length;
}
public Object getItem(int position){
return null;
}
public long getItemId(int position) {
return 0;
}
public View getView(int position, View convertView, ViewGroup parent) {
ImageView imageView;
if(convertView == null){
imageView = new ImageView(mContext);
imageView.setLayoutParams(new Gallery.LayoutParams(150, 120));
imageView.setScaleType(ImageView.ScaleType.CENTER_CROP);
imageView.setBackgroundResource(mGalleryItemBackground);
}
else {
imageView = (ImageView) convertView;
}
imageView.setImageResource(mGalleryIds[position]);
return imageView;
}
}
}
메인.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
>
<Gallery
android:id="@+id/gallery1"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
/>
<WebView
android:id="@+id/webview"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
/>
</LinearLayout>