Java 如何在单击按钮时更改imageview大小
我正在开发一个在中间显示图像的应用程序。 ImageView的xml代码如下所示Java 如何在单击按钮时更改imageview大小,java,android,xml,Java,Android,Xml,我正在开发一个在中间显示图像的应用程序。 ImageView的xml代码如下所示 <ImageView android:id="@+id/e_sym" android:layout_width="300px" android:layout_height="300px" android:rotation="0" android:contentDescription="@string/symbol_e" app:layout_constraint
<ImageView
android:id="@+id/e_sym"
android:layout_width="300px"
android:layout_height="300px"
android:rotation="0"
android:contentDescription="@string/symbol_e"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.499"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintVertical_bias="0.498"
app:srcCompat="@drawable/symbol_e" />
大小必须为像素格式您必须在
布局参数
中设置高度
和宽度
。检查以下内容:
decr.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
//code to change height and width values of the ImageView
imageView.getLayoutParams().height = 20;
imageView.getLayoutParams().width = 20;
imageView.requestLayout()
}
});
您只需在LayoutParams中提及imageView的宽度和高度
decr.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
//code to change height and width values of the ImageView
imageView.getLayoutParams().height = 50; //can change the size according to you requirements
imageView.getLayoutParams().width = 50; //--
imageView.requestLayout()
imageView.setScaleType(ImageView.ScaleType.CENTER_INSIDE);
}
});
这回答了你的问题吗@乌扎尔穆卡丹,有什么问题吗?你为什么要倒车?我的回答有问题吗?指出我的错误,这样我才能改正自己。谢谢
decr.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
//code to change height and width values of the ImageView
imageView.getLayoutParams().height = 50; //can change the size according to you requirements
imageView.getLayoutParams().width = 50; //--
imageView.requestLayout()
imageView.setScaleType(ImageView.ScaleType.CENTER_INSIDE);
}
});