Hi I had created a custom view as gallery item. My custom view contains an image view and a textview. I want textview to be below of imageview but it overlaps. Please how to do this
Custom_view.xml <?xml version="1.0" encoding="utf-8"?> <RelativeLayout android:id="@+id/widget28" android:layout_width="fill_parent" android:layout_height="fill_parent" xmlns:android="http://schemas.android.com/apk/res/android" > <ImageView android:id="@+id/imageview01" android:layout_width="96px" android:layout_height="86px" android:layout_alignParentTop="true" android:layout_alignParentLeft="true"> </ImageView> <TextView android:id="@+id/textview01" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="TextView" android:layout_below="@+id/imageview01" > </TextView> </RelativeLayout> Gallery.java package com.android.rss; import android.app.Activity; import android.content.Context; import android.content.res.TypedArray; import android.os.Bundle; import android.view.ContextMenu; import android.view.LayoutInflater; import android.view.MenuItem; import android.view.View; import android.view.ViewGroup; import android.view.ContextMenu.ContextMenuInfo; import android.view.ViewGroup.LayoutParams; import android.widget.AdapterView; import android.widget.BaseAdapter; import android.widget.Gallery; import android.widget.ImageView; import android.widget.LinearLayout; import android.widget.RelativeLayout; import android.widget.TextView; import android.widget.Toast; import android.widget.AdapterView.AdapterContextMenuInfo; import android.widget.AdapterView.OnItemClickListener; public class Gallery1 extends Activity { private class viewHolder{ private TextView text; private ImageView image; } Gallery g ; @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.gallery_1); // Reference the Gallery view g = (Gallery) findViewById(R.id.gallery); // Set the adapter to our custom adapter (below) g.setAdapter(new ImageAdapter(this)); // Set a item click listener, and just Toast the clicked position g.setOnItemClickListener(new OnItemClickListener() { public void onItemClick(AdapterView parent, View v, int position, long id) { Toast.makeText(Gallery1.this, "you have selected : " + position, Toast.LENGTH_SHORT).show(); } }); // We also want to show context menu for longpressed items in the gallery registerForContextMenu(g); } @Override public void onCreateContextMenu(ContextMenu menu, View v, ContextMenuInfo menuInfo) { menu.add("testing"); } @Override public boolean onContextItemSelected(MenuItem item) { AdapterContextMenuInfo info = (AdapterContextMenuInfo) item.getMenuInfo(); Toast.makeText(this, "Longpress: " + info.position, Toast.LENGTH_SHORT).show(); return true; } public class ImageAdapter extends BaseAdapter { int mGalleryItemBackground; private LayoutInflater mInflater; public ImageAdapter(Context c) { mContext = c; mInflater = LayoutInflater.from(c); // See res/values/attrs.xml for the <declare-styleable> that defines // Gallery1. TypedArray a = obtainStyledAttributes(R.styleable.Gallery1); mGalleryItemBackground = a.getResourceId( R.styleable.Gallery1_android_galleryItemBackground, 0); a.recycle(); } public int getCount() { return mImageIds.length; } public Object getItem(int position) { return position; } public long getItemId(int position) { return position; } public View getView(int position, View convertView, ViewGroup parent) { viewHolder viewholder= new viewHolder(); if (convertView == null) { LayoutInflater inflater = (LayoutInflater) mContext .getSystemService(Context.LAYOUT_INFLATER_SERVICE); convertView=inflater.inflate(R.layout.main, null,true); viewholder.image = (ImageView)convertView.findViewById(R.id.imageview01); viewholder.text = (TextView)convertView.findViewById(R.id.textview01); convertView.setTag(viewholder); } else{ viewholder= (viewHolder)convertView.getTag(); } convertView.setLayoutParams(new Gallery.LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT)); viewholder.image.setImageResource(mImageIds[position]); //viewholder.image.setScaleType(ImageView.ScaleType.FIT_XY); viewholder.image.setLayoutParams(new RelativeLayout.LayoutParams(136, 88)); viewholder.text.setLayoutParams(new RelativeLayout.LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT)); // The preferred Gallery item background // viewholder.image.setBackgroundResource(mGalleryItemBackground); viewholder.text.setText("POSITION : "+position); return convertView; } private Context mContext; private Integer[] mImageIds = { R.drawable.gallery_photo_1, R.drawable.gallery_photo_2, R.drawable.gallery_photo_3, R.drawable.gallery_photo_4, R.drawable.gallery_photo_5, R.drawable.gallery_photo_6, R.drawable.gallery_photo_7, R.drawable.gallery_photo_8 }; } } -- You received this message because you are subscribed to the Google Groups "Android Developers" group. To post to this group, send email to [email protected] To unsubscribe from this group, send email to [email protected] For more options, visit this group at http://groups.google.com/group/android-developers?hl=en

