Reputation: 61
i have a simple app that displays a table and below that displays an imageview with an image that changes depending on the row clicked on the table. It works and displays fine on the emulator but when i install it on my test phone it does not show. my code is here:
package com.coreservlets.widgets;
import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.ImageView;
import android.widget.TableRow;
import com.welly.keychords.R;
public class keya extends Activity
{
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.keya);
}
public void rowClick(View view) {
ImageView imagev = (ImageView) findViewById(R.id.imageView1);
switch(view.getId()) {
case R.id.one:
imagev.setImageResource(R.drawable.achord);
break;
case R.id.two:
imagev.setImageResource(R.drawable.bminor);
break;
case R.id.three:
imagev.setImageResource(R.drawable.csharpdbminor);
break;
case R.id.four:
imagev.setImageResource(R.drawable.dchord);
break;
case R.id.five:
imagev.setImageResource(R.drawable.echord);
break;
case R.id.six:
imagev.setImageResource(R.drawable.fsharpgbminor);
break;
case R.id.seven:
imagev.setImageResource(R.drawable.gsharpdim);
break;
}
}
}
my xml code is here:
<?xml version="1.0" encoding="utf-8"?>
<TableLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="#FF909090"
android:stretchColumns="1" >
<TableRow
android:id="@+id/one"
android:onClick="rowClick">
<TextView
android:layout_margin="2dip"
android:layout_marginRight="2dip"
android:background="#0000ff"
android:padding="3dip"
android:text="I" />
<TextView
android:layout_margin="2dip"
android:layout_marginLeft="1dip"
android:background="#0000ff"
android:gravity="center"
android:padding="3dip"
android:text="A"
/>
</TableRow>
<TableRow
android:id="@+id/two"
android:onClick="rowClick">
<TextView
android:layout_column="0"
android:layout_margin="2dip"
android:background="#0000ff"
android:padding="3dip"
android:text="II" />
<TextView
android:layout_margin="2dip"
android:background="#0000ff"
android:gravity="center"
android:padding="3dip"
android:text="Bm" />
</TableRow>
<TableRow
android:id="@+id/three"
android:onClick="rowClick">
<TextView
android:layout_column="0"
android:layout_margin="2dip"
android:background="#0000ff"
android:padding="3dip"
android:text="III" />
<TextView
android:layout_margin="2dip"
android:background="#0000ff"
android:gravity="center"
android:padding="3dip"
android:text="C#m" />
</TableRow>
<View
android:layout_height="2dip"
android:background="#FF909090" />
<TableRow android:background="#0000ff" >
</TableRow>
<TableRow
android:id="@+id/four"
android:onClick="rowClick">
<TextView
android:layout_margin="2dip"
android:background="#0000ff"
android:padding="3dip"
android:text="IV" />
<TextView
android:layout_margin="2dip"
android:background="#0000ff"
android:gravity="center"
android:padding="3dip"
android:text="D" />
</TableRow>
<View
android:layout_height="2dip"
android:background="#FF909090" />
<TableRow
android:id="@+id/tableRow1"
android:layout_width="wrap_content"
android:layout_height="wrap_content" >
</TableRow>
<TableRow
android:id="@+id/five"
android:onClick="rowClick">
<TextView
android:layout_margin="2dip"
android:layout_marginRight="2dip"
android:background="#0000ff"
android:padding="3dip"
android:text="V" />
<TextView
android:layout_margin="2dip"
android:layout_marginLeft="1dip"
android:background="#0000ff"
android:gravity="center"
android:padding="3dip"
android:text="E" />
</TableRow>
<TableRow
android:id="@+id/six"
android:onClick="rowClick">
<TextView
android:layout_margin="2dip"
android:layout_marginRight="2dip"
android:background="#0000ff"
android:padding="3dip"
android:text="VI" />
<TextView
android:layout_margin="2dip"
android:layout_marginLeft="1dip"
android:background="#0000ff"
android:gravity="center"
android:padding="3dip"
android:text="F#m" />
</TableRow>
<TableRow
android:id="@+id/seven"
android:onClick="rowClick">
<TextView
android:layout_margin="2dip"
android:layout_marginRight="2dip"
android:background="#0000ff"
android:padding="3dip"
android:text="VII" />
<TextView
android:layout_margin="2dip"
android:layout_marginLeft="1dip"
android:background="#0000ff"
android:gravity="center"
android:padding="3dip"
android:text="G#dim" />
</TableRow>
<TextView
android:id="@+id/textView1"
android:layout_width="wrap_content"
android:layout_height="114dp"
android:background="#000000"
android:maxLines="10"
android:text="The relative minor of the Major key of A is F#m. The 12 bar blues progression in A is: \n A | A | A | A | D | D | A | A | E | D | A | E" />
<ImageView
android:id="@+id/imageView1"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:background="#ffffff" />
</TableLayout>
the code for the imageview is right at the bottom of the xml layout. Any help on how to debug this?
Upvotes: 3
Views: 2416
Reputation: 46
Perhaps a bit old, but this thread still helped me. I had the same problem. On the emulator my image, JPG, was showing perfectly. But on my phone the image was not displayed.
When I put a background color on my ImageView I did see the color on my phone, but no image.
Then I scaled down the image, from around 2000px width to 1000px width. And voila.. the image was visible.
It seems there are maximum image resoluations.
Upvotes: 0
Reputation: 61
ive solved it by changing the images to png format and making them 50% smaller. not sure why that works but it does!
Upvotes: 1
Reputation: 15774
This is just a guess, given that there can be other things that can go wrong - do you have drawables in the correct resource folder? Maybe you have images in the drawable-mdpi
or drawable-ldpi
folder that corresponds to the emulator and not in the drawable-hdpi
corresponding to the device.
To test, suggest you to create a drawable
folder (without any qualifier) and copy all the drawable files to that folder and check if you see the ImageView
.
Update:
Use the hierarchyviewer to check the properties of the UI elements.
Upvotes: 1
Reputation: 421
Is the image view simply not showing? does it seem to be cutoff? try setting android:weight="1.0" or whatever number you want to the imageview or put the whole thing in a scroll view. that will solve the problem if it is being cutoff.
also another suggestion...
try wrapping the whole table layout inside a linear layout, and pull out your text view and image view at the very end. I am not 100% sure but I think you're only supposed to have table row inside of a table layout... however since its working on the emulator, not too sure.
-edit-
try this (put your textview and imageview in a tablerow)... it might work.
<TableRow>
<TextView
android:id="@+id/textView1"
android:layout_width="wrap_content"
android:layout_height="114dp"
android:background="#000000"
android:maxLines="10"
android:text="The relative minor of the Major key of A is F#m. The 12 bar blues progression in A is: \n A | A | A | A | D | D | A | A | E | D | A | E" />
</TableRow>
<TableRow>
<ImageView
android:id="@+id/imageView1"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:background="#ffffff" />
</TableRow>
Upvotes: 0
Reputation: 6668
contain all the views in the xml (except the layout itself) in a scrollview. Maybe your phone screen height is not too large.
Upvotes: 0