Android ImageView两种宽度

问题描述 投票:0回答:1

我们可以在Android中将两个宽度应用于ImageView吗?

enter image description here

我在网上大量搜索了解决方案,但我通过可绘制文件获得了1或2个解决方案。但是我不想用drawable来做,因为我想在运行时从seekbar值更改ImageView宽度。我的应用程序中有两个搜索栏,一个在ImageView上从顶部更改宽度,而另一个从底部更改宽度。

我也尝试过以下内容:

public class CustomImage extends AppCompatImageView {
    private Path path;

    public CustomImage(Context context) {
        super(context);
        init();
    }

    public CustomImage(Context context, AttributeSet attrs) {
        super(context, attrs);
        init();
    }

    public CustomImage(Context context, AttributeSet attrs, int defStyleAttr) {
        super(context, attrs, defStyleAttr);
        init();
    }
    private void init(){
        path = new Path();
    }

    @Override
    protected void onDraw(Canvas canvas) {
        float h = getMeasuredHeight();
        float w = getMeasuredWidth();
        path.moveTo(0, 0);
        path.lineTo(w, 0);
        path.lineTo(w * 0.8f, h);
        path.lineTo(w * 0.2f, h);
        path.lineTo(0, 0);
        path.close();
        canvas.clipPath(path);
        super.onDraw(canvas);
    }
}

但是它不能按我的要求工作。请没有可绘制的解决方案,因为它无法在我的应用程序上使用。

java android android-layout imageview android-imageview
1个回答
-1
投票

enter image description here

使用Mothion布局实现此目的

Github Lib

© www.soinside.com 2019 - 2024. All rights reserved.