如何在代码中从底部和顶部降低图片的高度?我有一张坦克的图片,一个透明的和一个绿色的照片应该在彼此的顶部,只显示两张图片的一部分,所以看起来坦克是半满的。 下面是我的xml。我正在使用fuel_button_green和fuel_button_empty。
<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>
答案 0 :(得分: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>
答案 1 :(得分:0)
您可以尝试使用LayoutParam
ImageButton button = (ImageButton) findViewById(R.id.fuel_button_green);
button.getLayoutParams().height = XX;
或
btnsize = button.getLayoutParams();
btnsize.height = XX;
button.setLayoutParams(btnsize);
让我知道它是否适合你:) - 快乐编码!