2013-05-15 22 views
0

如何从代码底部和顶部降低图片的高度?我有两张坦克的照片,一张是透明的,一张是绿色的,应该是在彼此之上,只显示两张照片的一部分,所以看起来坦克已经满了。 以下是我的xml。我正在使用fuel_button_green和fuel_button_empty。android从底部和顶部减少图片的高度,代码为

<RelativeLayout 
     android:id="@+id/over_fuel_indication" 
     android:layout_width="140dp" 
     android:layout_height="270dp" 
     android:layout_marginLeft="150dp" 
     android:layout_marginTop="130dp" 
     android:weightSum="100" 
     android:orientation="vertical"> 

     <ImageButton 
      android:id="@+id/fuel_button_green" 
      android:layout_width="fill_parent" 
      android:layout_height="fill_parent" 
      android:src="@drawable/tank_green_small" 
      android:background="#000000" /> 

     <ImageButton 
      android:id="@+id/fuel_button_empty" 
      android:background="#000000" 
      android:layout_width="fill_parent" 
      android:layout_height="fill_parent" 
      android:src="@drawable/tank_empty_small"/> 


     <ImageButton 
      android:id="@+id/meter_img_butt" 
      android:contentDescription="@string/meter_img_butt" 
      android:layout_width="72dp" 
      android:layout_height="8dp" 
      android:layout_marginLeft="15dp" 
      android:background="#000000" 
      android:src="@drawable/meter_small_nodot" /> 

     <ImageButton 
      android:id="@+id/meter_dot_img_butt" 
      android:contentDescription="@string/meter_img_butt" 
      android:layout_width="16dp" 
      android:layout_height="16dp" 
      android:background="#000000" 
      android:src="@drawable/meter_small_dot" /> 

     <ImageButton 
      android:id="@+id/bar_img_butt" 
      android:layout_width="11dp" 
      android:layout_height="fill_parent" 
      android:layout_marginLeft="121dp" 
      android:contentDescription="@string/bar_img_butt" 
      android:background="#000000" 
      android:src="@drawable/bar_small" /> 

     </RelativeLayout> 
+1

这应该用动画来完成。 –

回答

0

动画XML看起来是这样的:

<?xml version="1.0" encoding="utf-8"?> 
<set 
    xmlns:android="http://schemas.android.com/apk/res/android" 
    android:fillAfter="true" 
    android:duration="400"> 
    <scale 
     android:fromYScale="1" 
     android:toYScale="0.5" 
     android:pivotY="50%"/> 
</set> 
+0

谢谢!我用剪辑来获得它的工作。我不得不以编程方式更改大小。 –

0

你可以尝试使用LayoutParam

ImageButton button = (ImageButton) findViewById(R.id.fuel_button_green); 

button.getLayoutParams().height = XX; 

btnsize = button.getLayoutParams(); 
btnsize.height = XX; 
button.setLayoutParams(btnsize); 

让我知道它是否适合你:) - 快乐编码!

相关问题