SORU
13 Ocak 2011, PERŞEMBE


Nasıl üç GÖRÜNTÜ Ekran en boy oranını koruyarak genelinde germek için?

Aynı üç boyutlu görüntü (200 X 100) (arada boşluk yok) ekranın üst kısmında yan yana görüntülemek istiyorum. Ekranın tüm genişliğini kaplayacak ve en boy oranını korumak gerekir. Tek düzen xml dosyası kullanarak, ya da java kodu kullanmak istiyorum bunu yapmak mümkün müdür?
Çözünürlük bağımsız olması gerekir çözüm. kimseye (veya benzer) bu problemin çözümü veya bir link gönderebilir Miyim? Teşekkürler!

CEVAP
14 Ocak 2011, Cuma


Çalışıyor! Ama yukarıda da dediğim gibi, kendi sınıf oluşturmanız gerekir. Ama oldukça küçük. Bu yazı bu Bob Lee'nin cevap yardımıyla oluşturdum: Android: How to stretch an image to the screen width while maintaining aspect ratio?

package com.yourpackage.widgets;

import android.content.Context;
import android.util.AttributeSet;
import android.widget.ImageView;

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) {
        int width = MeasureSpec.getSize(widthMeasureSpec);
        int height = width * getDrawable().getIntrinsicHeight() / getDrawable().getIntrinsicWidth();
        setMeasuredDimension(width, height);
    }
}

Şimdi XML kullanmak için:

<com.yourpackage.widgets.AspectRatioImageView 
    android:id="@ id/image"
    android:src="@drawable/yourdrawable" 
    android:layout_width="match_parent" 
    android:layout_height="wrap_content"
    android:layout_alignParentTop="true" 
    android:layout_centerHorizontal="true" 
    android:adjustViewBounds="true" />

İyi eğlenceler!

=====================================

Başka bir şekilde android kullanarak XML aynı sadece bunu buldum:="". gerçek adjustViewBounds İşte bir örnek:

<LinearLayout
    android:layout_width="match_parent"
    android:layout_height="wrap_content" >

    <ImageView
        android:layout_width="0dp"
        android:layout_height="wrap_content"
        android:layout_weight="1"
        android:adjustViewBounds="true"
        android:src="@drawable/image1" />

    <ImageView
        android:layout_width="0dp"
        android:layout_height="wrap_content"
        android:layout_weight="1"
        android:adjustViewBounds="true"
        android:src="@drawable/image2" />


    <ImageView
        android:layout_width="0dp"
        android:layout_height="wrap_content"
        android:layout_weight="1"
        android:adjustViewBounds="true"
        android:src="@drawable/image2" />

</LinearLayout>

Bunu Paylaş:
  • Google+
  • E-Posta
Etiketler:

YORUMLAR

SPONSOR VİDEO

Rastgele Yazarlar

  • Helen Bradley

    Helen Bradle

    4 Mart 2008
  • kidrauhl

    kidrauhl

    15 Ocak 2007
  • Kontor.TV

    Kontor.TV

    14 Mart 2006