这几天,我正在开发一个应用程序,我必须添加一个视图,该视图必须显示从右到左的气流,而气流宽度必须从右到左改变。这是我的对象的xml代码;
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="164dp"
android:layout_height="wrap_content"
android:gravity="right">
<ImageView
android:id="@+id/img_exfan_status"
android:layout_width="16dp"
android:layout_height="16dp"
android:layout_marginLeft="88dp"
android:layout_marginTop="40dp"
android:src="@mipmap/green" />
<ImageView
android:id="@+id/img_exfan_battery"
android:layout_width="16dp"
android:layout_height="16dp"
android:layout_marginLeft="88dp"
android:layout_marginTop="20dp"
android:src="@drawable/if_battery_empty" />
<ImageView
android:id="@+id/img_exfan_link"
android:layout_width="16dp"
android:layout_height="16dp"
android:layout_marginLeft="88dp"
android:src="@mipmap/ethernet_off" />
<ImageView
android:id="@+id/img_exfan"
android:layout_width="56dp"
android:layout_height="56dp"
android:layout_marginLeft="32dp"
android:src="@mipmap/fan" />
<ImageView
android:id="@+id/img_exfan_flow"
android:layout_width="36dp"
android:layout_height="56dp"
android:gravity="end"
android:background="@mipmap/exfan_flow" />
<ImageView
android:id="@+id/img_setting"
android:layout_width="24dp"
android:layout_height="24dp"
android:layout_marginLeft="80dp"
android:layout_marginTop="60dp"
app:srcCompat="@mipmap/setting_icon" />
</RelativeLayout>
这是我对此对象的Java代码;
public class ViewExhaustFan extends RelativeLayout {
public ViewExhaustFan(Context context) {
super(context);
initialize(context);
}
public ViewExhaustFan(Context context, AttributeSet attrs) {
super(context, attrs);
initialize(context);
}
private void initialize(Context context) {
ImageView rootView = inflate(context, R.layout.object_exhaust_fan, this);
ImageView img_exfan = (ImageView) rootView.findViewById(R.id.img_exfan);
ImageView img_exfan_link = (ImageView) rootView.findViewById(R.id.img_exfan_link);
ImageView img_exfan_status = (ImageView) rootView.findViewById(R.id.img_exfan_status);
ImageView img_exfan_flow = (ImageView) rootView.findViewById(R.id.img_exfan_flow);
ImageView img_exfan_battery = (ImageView) rootView.findViewById(R.id.img_exfan_battery);
ImageView img_setting = (ImageView) rootView.findViewById(R.id.img_setting);
changeFlowSize(img_exfan_flow, -100);
//changeFlowSize(img_exfan_flow, 100);
}
public void changeFlowSize(ImageView image, int size){
LayoutParams params = (LayoutParams) image.getLayoutParams();
params.width = size;
image.setLayoutParams(params);
}
}
我尝试使用负值将气流图像从右向左更改,但是没有用。我该怎么做?
先谢谢了。