2014-02-22 58 views
0

我的android游戏上的精灵设置为每100毫秒降低5个像素,这很好,唯一的问题是ImageView本身只有53dp高,如果我让它内部的图像变大与它成比例。由于ImageView只有53dp高,图像在1100毫秒后消失,因为它在图像视图的边界之外滚动。Android XML - ImageView滚动

我需要的ImageView的布局高度FILL_PARENT,但我需要的形象留,而不是与它的缩放大小相同,这是我当前的代码:

<ImageView 
    android:id="@+id/blueman" 
    android:layout_width="0dip" 
    android:layout_height="53dp" 
    android:paddingRight="300dp" 
    android:layout_weight="0.03" 
    android:src="@drawable/fall" /> 

感谢提前:)

回答

0

因为你没有给出布局的完整代码,我会做一些假设...... 你说的是将精灵的高度设置为屏幕的高度而不缩放?

屏幕大小(即根布局项目)和其中的精灵应该有所不同。我猜你宣布你的布局...:

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" 
style="?gameBackground" 
android:layout_width="match_parent" 
android:layout_height="match_parent" 
android:orientation="vertical" > 

<Button 
    android:id="@+id/btTap" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:layout_alignParentLeft="true" 
    android:layout_alignParentTop="true" 
    android:layout_marginLeft="14dp" 
    android:layout_marginTop="350dp" 
    android:background="@drawable/tap" 
    android:visibility="visible" /> 

<Button 
    android:id="@+id/btCellR1C1" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:layout_alignParentLeft="true" 
    android:layout_alignParentTop="true" 
    android:layout_marginLeft="490dp" 
    android:layout_marginTop="155dp" 
    android:background="@drawable/cell_red" /> 

我不得不面对的唯一的事情,是根据设备的分辨率,这样的方法我精灵的缩放:

public static void scaleView(View view, int top, int left, int width, 
     int height) { 
    top = Math.round(top * scaleY); 
    left = Math.round(left * scaleX); 
    width = Math.round(width * scaleX); 
    height = Math.round(height * scaleY); 

    LayoutParams params = new LayoutParams(LayoutParams.WRAP_CONTENT, 
      LayoutParams.WRAP_CONTENT); 
    params.height = height; 
    params.width = width; 
    params.topMargin = top; 
    params.leftMargin = left; 
    view.setLayoutParams(params); 

    view.setSoundEffectsEnabled(false); 
} 

请给我们更多的细节,以帮助您

问候 塞尔