2012-01-14 75 views
0

我'使用全屏和鎖定肖像。在清單:Imageview的位置不像預期的那樣

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

在佈局我有一個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> 

一開始我打開我自己的形象進入的ImageView:

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

在兩個我的模擬器按預期在屏幕頂部顯示圖像。

我然後制定一個位圖和替換圖像:

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

這是因爲你的圖片對於屏幕來說太大了。

在XML中設置android:adjustViewBounds="true"可能會有所幫助。

此外,您可以嘗試獲取屏幕寬度和使用它:

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); 

爲了簡化代碼一點點。

相關問題