0

I created an app, it's finely working as what i want on minsdkversion="3". But other activities look even bigger than usual. If i change the minsdkversion="8" or something, the other activities looks as normal, but i didn't get the output i want.

Following is the code for gridview and imageview layout files:

activity_main.xml:

<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >

<GridView
    android:id="@+id/grid_View"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:horizontalSpacing="0dp"
    android:numColumns="4"
    android:stretchMode="columnWidth"
    android:verticalSpacing="0dp"
    android:gravity="center_horizontal"
    android:clipChildren="true" >

</GridView>

</LinearLayout>

grid.xml:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical" >

<ImageView
    android:id="@+id/image_View"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_gravity="center"
    android:layout_weight="0.05"/>
</LinearLayout>

MainActivity.java:

public View getView(int position, View convertView, ViewGroup parent)
    {
        ImageView imageView;

        if (convertView == null)
        {
            imageView = new ImageView(mContext);
            imageView.setLayoutParams(new GridView.LayoutParams(LayoutParams.WRAP_CONTENT,LayoutParams.WRAP_CONTENT));
            i = i+1;
            imageView.setId(i);
            Log.d("=====  i value =====", String.valueOf(i));
            imageView.setAdjustViewBounds(true);
            imageView.setScaleType(ImageView.ScaleType.CENTER_CROP);
        }
        else
        {
            imageView = (ImageView) convertView;
        }

        imageView.setImageResource(mThumbIds[position]);

        return imageView;
    }

What is the wrong with my code, what i have to change?

Abdul Rahman
  • 2,097
  • 4
  • 28
  • 36
  • A `GridView` is not designed to provide seamless contiguous image regions, as your screenshots suggest you are trying to do. – CommonsWare Jan 27 '13 at 15:56
  • @CommonsWare: So how can i achieve it? I have to show some toast when particular body part is pressed, i thought to achieve it through GridView. – Abdul Rahman Jan 27 '13 at 16:24

1 Answers1

3

I have to show some toast when particular body part is pressed

Step #1: Display the body in an ImageView

Step #2: Override onTouchEvent() in your activity or fragment that is managing the ImageView

Step #3: Determine the body part based on the location of the touch event and the size of the ImageView, and display your Toast

CommonsWare
  • 986,068
  • 189
  • 2,389
  • 2,491