2012-01-14 3 views
0

私はフルスクリーンを使用し、ポートレートにロックしています。マニフェストでは:両方で画像ビューの位置が期待どおりに動作しない

imageView = (ImageView) findViewById(R.id.imageView1); //from .xml 
Drawable newPhoneImage; 
newPhoneImage = getResources().getDrawable(R.drawable.phone_on); 
imageView.setImageDrawable(newPhoneImage); 

:私はImageViewのに自分のイメージをロード開始時

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
android:layout_width="fill_parent" 
android:layout_height="fill_parent" 
android:orientation="vertical" > 
<ImageView 
    android:id="@+id/imageView1" 
    android:layout_width="fill_parent" 
    android:layout_height="wrap_content" 
    android:layout_gravity="center_vertical"/> 
<Button 
    android:id="@+id/button1" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:text="Button" /> 
<Button 
    android:id="@+id/button2" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:text="Button" /> 
</LinearLayout> 

android:theme="@android:style/Theme.NoTitleBar.Fullscreen" 
android:screenOrientation="portrait" 

レイアウトで私はImageViewのと2つのボタンがあります私のエミュレータは、画面の上部にイメージを表示します。

私は、ビットマップを策定し、イメージを置き換える:

sBitmap = Bitmap.createBitmap(557, 580,Config.ARGB_8888); 
//draw the bimap image 
BitmapDrawable nimage; 
nimage = new BitmapDrawable(sBitmap); 
imageView.setImageDrawable(nimage); 

を大エミュレータ(WVGA800 400x800)期待通りの画像が一番上にあるで。

小型エミュレータ(QVGA 240x320)と携帯電話(240x320)では、画像は上から35ピクセル下にあります。

なぜ異なるのですか?

私は、画像をスクロールアップすることができます

imageView.scrollTo(0, 35); //this will put image at top 

をどのように私は、この値を見つけることができますか?このようなものは動作しません。

int offset = imageView.getTop();// it just = height of image 

助けてください。

答えて

0

画像が画面に対して大きすぎるためです。

android:adjustViewBounds="true"をXMLで設定すると役立ちます。

Display display = getWindowManager().getDefaultDisplay(); 
int width = display.getWidth(); 
Bitmap.createBitmap(width, width/557*580,Config.ARGB_8888); 

を正しいサイズの画像を作成するには:

また、あなたは画面の幅を取得し、それを使用してみてください。これらの両方の設定を同時に試してみてください。別のノートで

、あなたができるだけ:

imageView = (ImageView) findViewById(R.id.imageView1); //from .xml 
imageView.setImageResource(R.drawable.phone_on); 

コードを少し簡単にするために。