繁体   English   中英

从顶部和底部分开更改 ImageView 宽度

[英]Change ImageView Width from top and bottom seperate

我试图分别从顶部和底部更改ImageView的宽度。 我想要从左上角到 100dp 和从左下角到 50dp 的宽度。 有关想法,请参阅附图:

]

我试图在网上找到解决方案,但我还没有找到任何东西。 我尝试使用 Android Scale 库,但无法获得所需的结果。

ScaleAnimation fade_in =  new ScaleAnimation(0f, 1f, 0f, 1f, Animation.RELATIVE_TO_SELF, 0.5f, Animation.RELATIVE_TO_SELF, 0.5f);
        fade_in.setDuration(1000);     // animation duration in milliseconds
        fade_in.setFillAfter(true);    // If fillAfter is true, the transformation that this animation performed will persist when it is finished.
        IV.startAnimation(fade_in);

请指导我哪个图书馆能够做到这一点或如何实现?

您可以使用此库创建自定义形状ImageView

您必须为您的背景图像视图创建一个 XML 文件并塑造 Trapezius。 你不必使用任何库。

注意:因为你,我使用了颜色来表示实体等等(将它复制并粘贴到你的 XML 文件中并观看它)。

<layer-list xmlns:android="http://schemas.android.com/apk/res/android" >
<item>
    <shape android:shape="rectangle">
        <padding android:top="35dp"/>
        <size android:width="200dp" android:height="40dp" />
        <solid android:color="#13a89e" />
    </shape>
</item>

<item>
    <shape android:shape="line">
        <size android:width="100dp"/>
        <stroke android:width="4dp" android:color="#123456" />
    </shape>
</item>

<item
    android:right="-200dp"
    android:left="200dp"
    android:top="-200dp"
    android:bottom="-200dp">
    <rotate android:fromDegrees="45">
        <shape android:shape="rectangle">
           <padding android:top="-35dp"/>
           <solid android:color="#ffffff" />
        </shape>
    </rotate>
</item>
<item
    android:right="200dp"
    android:left="-200dp"
    android:top="-200dp"
    android:bottom="-200dp">
    <rotate android:fromDegrees="-45">
        <shape android:shape="rectangle">
            <padding android:top="-35dp"/>
            <solid android:color="#ffffff" />
        </shape>
    </rotate>
</item>
</layer-list>

我认为您可以创建自定义Imageview并使用自定义Imageview您可以根据您的要求使用ValueAnimator使用动画和动画path进行ValueAnimator

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


}

在此处输入图片说明

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM