2016-03-19 24 views
-1

グリッドビューにイメージサムネイルを設定しようとしています。子アイテムを中央に配置することができず、画像の向きが異なる場合(風景と肖像)の不一致が発生します。写真はどのように出てくるかを示しています。サムネイルのサイズを変更するのではなく、テキストビューを同じレベルに表示し、イメージビューを中央に合わせて表示したい。グリッドビュー内の子アイテムのセンタリング

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クラス:

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の子のレイアウト:

<?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" /> 

これに関するお手伝いをお待ちしております。私はそのような問題を探してみましたが、提供されているソリューションのいずれかで問題を解決できませんでした。

+0

私はあなたの意見が中心にあるように見えますが、それらは同じサイズではありません。 78dpのようにImageViewの高さを固定してみましたか? –

+0

高さを100dpに設定すると機能します。ありがとう:) –

答えて

1

ImageViewの高さを100dpに設定します。ありがとう:)

+0

あなたの質問に答えてください。 –

0

固定幅を設定し、重力を中央に設定するだけです。 android:layout_width = "8" and android:gravity = "center"

関連する問題