【问题标题】:Android ImageView and ImageButton ScalingAndroid ImageView 和 ImageButton 缩放
【发布时间】:2016-04-13 07:12:55
【问题描述】:

对于 Android Image View .. 如何缩放 1081*373 Image Button 以匹配 Image View 的宽度并固定高度??

如果图像按钮,我尝试匹配父宽度,但它的细节没有出现......看起来像缩放图像??并且不能使用重力??

<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"



    />

【问题讨论】:

    标签: android imageview imagebutton


    【解决方案1】:

    试试吧!

    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);
    }
    

    }

    在xml中

    <your.package.MyBanner
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:src="@drawable/about"/>
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2012-08-23
      • 1970-01-01
      • 1970-01-01
      • 2013-01-06
      • 2020-05-15
      • 2014-03-05
      • 1970-01-01
      相关资源
      最近更新 更多