2016-04-02 12 views
0

私は正しく動作するgridviewのクラスを作成し、正しく動作しているアプリケーションの他の部分でテストします。カスタムレイアウトには、私がテストする部分にのみimageViewが含まれています。私は一緒にImageViewのとのTextViewの両方を使用する必要が活動のために、ここでのXMLコードandroidの表示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="wrap_content" 
android:weightSum="1" 
android:orientation="vertical"> 

<ImageView 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:id="@+id/imageView3" 
    android:layout_gravity="center_horizontal" 
    android:src="@drawable/khattesevom" /> 

<TextView 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:textAppearance="?android:attr/textAppearanceMedium" 
    android:text="Medium Text" 
    android:id="@+id/textView5" 
    android:background="@drawable/textblockbio" 
    android:textColor="@color/colorText" 
    android:layout_gravity="center_horizontal" 
    android:padding="5dp" /> 
</LinearLayout> 

私のクラスのコード:

GridView gridView = (GridView) tb2.findViewById(R.id.gridView4); 
    String[] t = {"Marham", "Onam Mesle Mane", "Mikham", "Door", "To Besh Migi Mariz", "Oraman", "Test"}; 
    int[] img = {R.drawable.ic_khattesevom, R.drawable.ic_khattesevom, R.drawable.ic_khattesevom, R.drawable.ic_khattesevom, R.drawable.ic_khattesevom, R.drawable.ic_khattesevom, R.drawable.ic_khattesevom}; 
    gridView.setAdapter(new GridLyrics(getContext(), t, img)); 

public class GridLyrics extends BaseAdapter { 
private Context mContext; 
private final String[] title; 
private final int image[]; 
public GridLyrics(Context context, String[] t, int[] img) 
{ 
    mContext = context; 
    this.title = t; 
    this.image = img; 
} 
@Override 
public int getCount() { 
    return title.length; 
} 

@Override 
public Object getItem(int position) { 
    return null; 
} 

@Override 
public long getItemId(int position) { 
    return 0; 
} 

@Override 
public View getView(int position, View convertView, ViewGroup parent) { 

    View grid; 
    LayoutInflater inflater = (LayoutInflater) mContext.getSystemService(Context.LAYOUT_INFLATER_SERVICE); 


    if (convertView == null) 
    { 
     grid = new View(mContext); 
     grid = inflater.inflate(R.layout.grid_lyrics, parent, false); 

     TextView textView = (TextView) grid.findViewById(R.id.textView5); 
     ImageView imageView = (ImageView)grid.findViewById(R.id.imageView3); 
     textView.setText(title[position]); 
     imageView.setImageResource(image[position]); 
    } 
    else 
    { 
     grid = (View) convertView; 
    } 

    return grid; 
} 
} 

、ここでは、私はそれを使用する方法です

私の問題は、テキスト行が表示されない最終行にあります!画像は表示されますが、textViewは表示されません。

the picture of app 私は何ができるのですか?

enter image description here

答えて

0

これはどうですか。あなたはmatch parent に彼の名前

+0

いいえ正しく動作しません –

+0

なぜですか? Plsは少し説明します。ありがとう。 –

+0

最初のサイズですが、1行しか表示されませんが、他のアイテムを見るためにスクロールすることができます。 –

1

セットTextView高さを取得し、詰め物を取り除くことができるだろうし、スクロールダウンしてLinearLayoutScrollViewにそのように変更します。 あなたのxmlを以下のように変更してください。

<?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="wrap_content" 
android:weightSum="1" 
android:orientation="vertical"> 

<ImageView 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:id="@+id/imageView3" 
    android:layout_gravity="center_horizontal" 
    android:src="@drawable/khattesevom" /> 

<TextView 
    android:layout_width="wrap_content" 
    android:layout_height="match_parent" 
    android:textAppearance="?android:attr/textAppearanceMedium" 
    android:text="Medium Text" 
    android:id="@+id/textView5" 
    android:background="@drawable/textblockbio" 
    android:textColor="@color/colorText" 
    android:layout_gravity="center_horizontal" 
    /> 
</LinearLayout> 

私はそれがあなたのために働くと思います。

関連する問題