2016-03-19 11 views
-1

Resim küçük resimlerle ızgara görünümü oluşturmaya çalışıyorum. Çocuk öğelerini ortalayamıyorum ve görüntü yönelimi farklı olduğunda, yani manzaraya göre portre arasında bir uyumsuzluk ortaya çıkıyor. Resim nasıl ortaya çıktığını gösterir. Küçük resimlerin boyutunu değiştirmek istemiyorum, ancak aynı seviyedeki metin görünümünü ve buna göre ortalanacak görüntü görünümünü görüntülemek istiyorum.gridview içinde alt öğeleri ortalamak

photo gridview with childs not centered

Gridview XML:

<syook.syookfirst.classes.Utils.ExpandableHeightGridView 
     android:layout_width="match_parent" 
     android:layout_height="match_parent" 
     android:id="@+id/listview_call_photos" 
     android:layout_marginLeft="2dp" 
     android:layout_marginRight="2dp" 
     android:layout_weight="1" 
     android:nestedScrollingEnabled="true" 
     android:gravity="center" 
     android:layout_gravity="center" 
     android:numColumns="auto_fit"> 

    </syook.syookfirst.classes.Utils.ExpandableHeightGridView> 

ExpandableHeightGridView sınıfı:

public class ExpandableHeightGridView extends GridView 
{ 

boolean expanded = false; 

public ExpandableHeightGridView(Context context) 
{ 
    super(context); 
} 

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

public ExpandableHeightGridView(Context context, AttributeSet attrs, int defStyle) 
{ 
    super(context, attrs, defStyle); 
} 

public boolean isExpanded() 
{ 
    return expanded; 
} 

@Override 
public void onMeasure(int widthMeasureSpec, int heightMeasureSpec) 
{ 
    // HACK! TAKE THAT ANDROID! 
    if (isExpanded()) 
    { 
     // Calculate entire height by providing a very large height hint. 
     // But do not use the highest 2 bits of this integer; those are 
     // reserved for the MeasureSpec mode. 
     int expandSpec = MeasureSpec.makeMeasureSpec(Integer.MAX_VALUE >> 2, MeasureSpec.AT_MOST); 
     super.onMeasure(widthMeasureSpec, expandSpec); 

     ViewGroup.LayoutParams params = getLayoutParams(); 
     params.height = getMeasuredHeight(); 
    } 
    else 
    { 
     super.onMeasure(widthMeasureSpec, heightMeasureSpec); 
    } 
} 

public void setExpanded(boolean expanded) 
{ 
    this.expanded = expanded; 
} 
} 

Gridview çocuk düzeni:

<?xml version="1.0" encoding="utf-8"?> 
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    android:orientation="vertical" 
    android:background="@drawable/button_pressed_nocolor_all" 
    android:gravity="center"> 

<ImageView 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:id="@+id/photo_thumb_calldetails" 
    android:padding="5dp" 
    android:layout_gravity="center" /> 

<TextView 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:id="@+id/label_photo_name" 
    android:textSize="12sp" 
    android:layout_gravity="center" 
    android:gravity="center" 
    android:padding="2dp" 
    android:layout_marginBottom="2dp" /> 

Bu konuda herhangi bir yardım için teşekkür ederiz. Bu tür konuları aramayı denedim, ancak sağlanan çözümlerden herhangi birini çözemedim.

+0

Görünümünüz ortalanmış gibi görünüyor ama aynı boyutta değiller. Örneğin ImageView gibi 78dp için sabit bir yükseklik koymaya çalıştınız mı, nasıl göründüğünü görüyor musunuz? –

+0

Yüksekliği 100dp'ye ayarlar. Teşekkürler :) –

cevap

1

ImageView'in yüksekliğini 100dp'ye ayarlamak çalışır. Teşekkürler :)

+0

Sorunuzu cevaplandı olarak işaretleyebilir misiniz lütfen? –

0

Sadece düzeltme genişliğini ayarlayın ve yerçekimini merkeze ayarlayın. android: layout_width = "8" ve android: yerçekimi = "merkez"