【问题标题】:android decrease the height of a picture from bottom and from top, in codeandroid在代码中从底部和顶部降低图片的高度
【发布时间】:2013-05-15 17:42:54
【问题描述】:

如何在代码中从底部和顶部减小图片的高度?我有两张坦克的照片,一张是透明的,一张是绿色的,它们应该在彼此的顶部,并且只显示两张照片的一部分,所以看起来坦克是半满的。 下面是我的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>

【问题讨论】:

  • 这应该用动画来完成。

标签: android height


【解决方案1】:

动画 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>

【讨论】:

  • 谢谢!我用剪辑让它工作。我必须以编程方式更改大小。
【解决方案2】:

您可以尝试使用LayoutParam

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

button.getLayoutParams().height = XX;

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

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

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2020-10-03
    • 2018-03-31
    • 1970-01-01
    • 1970-01-01
    • 2018-05-16
    • 1970-01-01
    • 2013-02-04
    • 1970-01-01
    相关资源
    最近更新 更多