私はimageview
を持っています。 私はimageView.setScaleX()
を使用しましたが、この方法は画像内の画像のみを拡大し、画像ビューX、Y、幅、高さは同じです。 画像でimageview
のサイズを変更するにはどうすればよいですか?AndroidスケールImageViewのフレーム
0
A
答えて
0
T @saeidからのハンクス。私はsetScaleをsetWidthに置き換えて、私の問題を解決しました。
0
あなたはこのようImageViewのをXMLにプロパティscaleTypeを追加することができます。
android:scaleType="fitXY"
さらに詳しい情報:
https://robots.thoughtbot.com/android-imageview-scaletype-a-visual-guide
https://developer.android.com/reference/android/widget/ImageView.ScaleType.html
+0
私はイメージを表示するために問題はありません。スケールを使って画像の境界を調整したい。 – ali
0
幅を変更したときに高さを自動的に変更したい場合は、このカスタムImageViewを使用してください。
import android.content.Context;
import android.util.AttributeSet;
import android.widget.ImageView;
import java.lang.reflect.Field;
public class AspectRatioImageView extends ImageView {
public AspectRatioImageView(Context context) {
super(context);
}
public AspectRatioImageView(Context context, AttributeSet attrs) {
super(context, attrs);
}
public AspectRatioImageView(Context context, AttributeSet attrs,
int defStyle) {
super(context, attrs, defStyle);
}
@Override
protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
try {
int width = MeasureSpec.getSize(widthMeasureSpec);
int height = width * getDrawable().getIntrinsicHeight()
/getDrawable().getIntrinsicWidth();
int maxHeight;
try {
Field f = ImageView.class.getDeclaredField("mMaxHeight");
f.setAccessible(true);
maxHeight = (Integer) f.get(this);
} catch (NoSuchFieldException e) {
maxHeight = Integer.MAX_VALUE;
}
setMeasuredDimension(width, height > maxHeight ? maxHeight : height);
} catch (Exception e) {
super.onMeasure(widthMeasureSpec, heightMeasureSpec);
}
}
}
関連する問題
- 1. Androidのアニメーションの最初のフレームが早すぎるImageViewの
- 2. Android、ImageView over ImageView
- 3. プログラムでスケールとスクロール(ImageView)を設定
- 4. ImageViewスケールでのAndroid共有要素の移行が間違っています
- 5. ImageVIewフレームにコーナーのみを描く
- 6. android imageView
- 7. Androidスケールの問題
- 8. Android UIスケール
- 9. android opengl esスケール
- 10. 2x2 imageviewのGridlayout android
- 11. ImageView Android上のボタン
- 12. Android dimsissスワイプジェスチャーのImageView
- 13. Android ImageViewの問題
- 14. Android imageview longpressヒント
- 15. Android ImageViewズームインアイコン
- 16. Android ImageView scalling
- 17. Android ImageView setImageBitmap
- 18. Android ImageView - 16:9
- 19. android imageview onclickリスナー
- 20. AndroidスタジオImageView onDraw
- 21. Android用ウィジェットアニメーションImageView
- 22. Android square imageview
- 23. Android ImageViewビットマップアップスケールモード
- 24. Android ImageView ScaleType * FIT_TOP *
- 25. Android ImageViewホットスポットマッピング
- 26. Android ImageViewフリッピングアニメーション
- 27. imageview android 2.1
- 28. android - scaling ImageView
- 29. Android ImageView Nearest Neighbor
- 30. Android:カスタムImageView
画像ビューのいくつかのプロパティを既に確認してください。 – Saveen
なぜscaleXを変更しないのですか? – Saeid
android:scaleType = "center"を設定します。 –