내 갤러리에 두 개의 갤러리 뷰를 추가하고 싶습니다. 아래 이미지에서 보여 주듯이 제 질문으로 명확하게 말하십시오. 위의 그림과 똑같은 이미지와 기능을 보여주는 이미지보기 아래에 또 다른 가로 스크롤보기를 추가하고 싶습니다.. 여기 하나의 활동에 두 개의 GalleryView 추가하기
내가 지금까지 가지고 올 한 코드입니다. 예 :은 개발자 샘플은입니다. 사소한 변화가 있습니다.public class Gallery2DemoActivity extends Activity {
private Gallery gallery,gallery1;
private ImageView imgView;
private Integer[] Imgid = {
R.drawable.a_1, R.drawable.a_2, R.drawable.a_3, R.drawable.a_4, R.drawable.a_5, R.drawable.a_6, R.drawable.a_7
};
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
gallery = (Gallery) findViewById(R.id.examplegallery);
gallery.setAdapter(new AddImgAdp(this));
gallery1 = (Gallery)findViewById(R.id.examplegallery1);
gallery1.setAdapter(new AddImgAdp(this));
imgView = (ImageView)findViewById(R.id.ImageView01);
imgView.setImageResource(Imgid[0]);
gallery.setOnItemClickListener(new OnItemClickListener() {
public void onItemClick(AdapterView parent, View v, int position, long id) {
imgView.setImageResource(Imgid[position]);
}
});
}
public class AddImgAdp extends BaseAdapter {
int GalItemBg;
private Context cont;
public AddImgAdp(Context c) {
cont = c;
TypedArray typArray = obtainStyledAttributes(R.styleable.GalleryTheme);
GalItemBg = typArray.getResourceId(R.styleable.GalleryTheme_android_galleryItemBackground, 0);
typArray.recycle();
}
public int getCount() {
return Imgid.length;
}
public Object getItem(int position) {
return position;
}
public long getItemId(int position) {
return position;
}
public View getView(int position, View convertView, ViewGroup parent) {
ImageView imgView = new ImageView(cont);
imgView.setImageResource(Imgid[position]);
imgView.setLayoutParams(new Gallery.LayoutParams(110, 100));
imgView.setScaleType(ImageView.ScaleType.FIT_XY);
imgView.setBackgroundResource(GalItemBg);
return imgView;
}
}
}
다음은 내 XML 파일입니다. 어느 것이 꽤 간단하고 단순합니다.
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/LinearLayout01"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical" >
<Gallery
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/examplegallery"
android:layout_width="fill_parent"
android:layout_height="wrap_content" />
<ImageView
android:id="@+id/ImageView01"
android:layout_width="fill_parent"
android:layout_height="fill_parent" />
<Gallery
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/examplegallery1"
android:layout_width="fill_parent"
android:layout_height="wrap_content" />
</LinearLayout>
두 개의 갤러리 뷰를 하나의 AddImg 어댑터로 설정할 수 있습니까?
어디로 잘못 가고 있습니까? 두 번째 수평 스크롤보기가 보이지 않습니다.
이 문제를 해결하려면 어떻게해야합니까?
현재 어떤 문제에 직면하고 있습니까? 예외가 발생했는지, 예상치 못한 동작이 발생했는지, 실행하면 어떻게 될지 알려주세요. –
@ AdilSoomro 하단의 두 번째 가로보기가 표시되지 않습니다. 나는 그것을 지적 해 주심에 감사드립니다. –
'ImageView'에는'android : layout_weight = "1"'이 필요합니다. –