![](/img/trans.png)
[英]SwipeGestureDetector change image from int [] to Imageview (Top & Bottom)
[英]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.