对于Android Image View ..如何缩放1081 * 373图像按钮以匹配图像视图的宽度并固定高度??
我尝试匹配父级宽度如果图像按钮,但它'细节不出现...看起来像缩放图像?并且不能使用重力?
<ImageView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:src="@drawable/mainempty"
/>
<ImageButton
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:src="@drawable/about"
/>
答案 0 :(得分:0)
试试吧!
public class MyBanner extends ImageView {
public MyBanner(Context context) {
super(context);
}
public MyBanner(Context context, AttributeSet attrs) {
super(context, attrs);
}
public MyBanner(Context context, AttributeSet attrs, int defStyle) {
super(context, attrs, defStyle);
}
@Override protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
int width = MeasureSpec.getSize(widthMeasureSpec);
int height = width * 373 / 1081;
setMeasuredDimension(width, height);
}
}
in xml
<your.package.MyBanner
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@drawable/about"/>