按钮包含具有不同尺寸的图像,用于向下和向上状态

时间:2014-06-18 09:13:02

标签: android android-layout

我有一个按钮,其中向下和向上状态非常不同 - 两个图像的尺寸不同,一种方法是检测触摸事件并根据需要替换两个图像。 我目前解决这个问题的想法是使用如下的FrameLayout并多次使用它:

<FrameLayout
    android:layout_width="wrap_content"
    android:layout_height="wrap_content">
    <ImageView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:id="@+id/btnSettingDown"
        android:src="@drawable/button_settings_down"
        android:layout_marginTop="647dp"
        android:layout_marginLeft="425dp"/>

    <ImageView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:id="@+id/btnSetting"
        android:src="@drawable/button_settings"
        android:layout_marginTop="657dp"
        android:layout_marginLeft="432dp"/>

</FrameLayout>

但是可以将它定义为模板或其他东西吗? 我有这样一个以上的按钮,如果这可以像一个自定义xml,可以有自定义属性,更容易在其他应用程序中重用,会更好。我需要能够为每个按钮的每个图像设置src,layout_marginTop和layout_marginLeft。

我对处理这个问题的其他提案持开放态度,但是让向下和向上状态保持相同的维度不是一种选择。

0 个答案:

没有答案
相关问题