2015-01-08 4 views
0

저는 Android에서 매우 새로 생겨서이 작업에 약간의 도움이 필요합니다.이미지와 텍스트가있는 GridView

나는 gridview 마녀가 데이터베이스에서 이미지와 텍스트를 가져 와서 표시합니다. 현재 이미지와 같이 표시되며 이미지의 오른쪽에는 텍스트가 표시됩니다. 이미지 아래에 텍스트를 만들고 싶습니다. 이 일을 도와 주실 수 있습니까? 이것은 gridview.xml

<LinearLayout 
    android:orientation="horizontal" 
    android:layout_width="fill_parent" 
    android:layout_height="wrap_content" 
    android:layout_weight="0.1" > 

    <GridView 
     android:id="@+id/gridView1" 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:horizontalSpacing="5dp" 
     android:verticalSpacing="5dp" 
     android:numColumns="2" > 

    </GridView>    
</LinearLayout> 

입니다 그리고 이것은 내가 그것을

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
android:orientation="horizontal" 
android:layout_width="fill_parent" 
android:layout_height="fill_parent" 
android:background="@drawable/bckimageviw" 
> 
<ImageView 
    android:id="@+id/ColPhoto" 
    android:layout_width="0dp" 
    android:layout_height="0dp" 

/> 
<LinearLayout 
    android:orientation="vertical" 
    android:layout_width="fill_parent" 
    android:layout_height="fill_parent"> 

     <TextView android:id="@+id/ColName" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:layout_marginTop="25dp" 
      android:text="Name" 
     /> 
</LinearLayout> 
</LinearLayout> 

을 table_column.xml 그리고 필요의 getView()

 public View getView(int position, View convertView, ViewGroup parent) { 
     // TODO Auto-generated method stub 

     LayoutInflater inflater = (LayoutInflater) context 
       .getSystemService(Context.LAYOUT_INFLATER_SERVICE); 


     if (convertView == null) { 
      convertView = inflater.inflate(R.layout.table_column, null); 
     } 

     // ColPhoto 
     ImageView imageView = (ImageView) convertView.findViewById(R.id.ColPhoto); 
     imageView.getLayoutParams().height = 80; 
     imageView.getLayoutParams().width = 80; 
     imageView.setPadding(10, 10, 10, 10); 
     imageView.setScaleType(ImageView.ScaleType.CENTER_CROP); 
     try 
     { 
      imageView.setImageBitmap((Bitmap)MyArr.get(position).get("ImageThumBitmap")); 
     } catch (Exception e) { 
      // When Error 
      imageView.setImageResource(android.R.drawable.ic_menu_report_image); 
     } 
     // ColName 
     TextView txtName = (TextView) convertView.findViewById(R.id.ColName); 
     txtName.setPadding(5, 0, 0, 0); 
     txtName.setText("" + MyArr.get(position).get("name").toString());  

     return convertView; 
    } 
+2

, 당신은 당신의 table_column.xml에서 두 번째있는 LinearLayout을 필요로하지 않는 방법으로) – Tr4X

+1

, 당신은 – Tr4X

답변

1

U 상대 배치를 사용 imageviewtextview 정렬로 설정할 수있다.

enter image description here

이 시도.

table_column.xml에서 메인의 LinearLayout, 수직으로 설정 방향
<?xml version="1.0" encoding="utf-8"?> 
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:background="#ff0000" 
    android:gravity="center" > 

    <ImageView 
     android:id="@+id/ColPhoto" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:layout_alignLeft="@+id/ColName" 
     android:layout_alignRight="@+id/ColName" 
     android:src="@drawable/ic_launcher" /> 

    <TextView 
     android:id="@+id/ColName" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:layout_below="@+id/ColPhoto" 
     android:gravity="center" 
     android:text="Name name" /> 

</RelativeLayout> 
+0

있는 LinearLayout 루트에 텍스트 뷰를 넣을 수 있습니다하지만, 텍스트가 –

+0

아래의 이미지 위에 있습니다. iamge 아래에 있습니까? –

+0

예, 이미지 아래에 텍스트를 넣으려고합니다. –

0

경우 변경하려고에서 이미지와 텍스트를 표시하는 방법입니다 방향을 "수직"으로하십시오.

편집 :

처럼, Tr4XLinearLayout 초 필요하지 않습니다 말했다. 둘 다 넣을 수 있습니다.

<?xml version="1.0" encoding="utf-8"?> 
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
android:orientation="vertical" 
android:layout_width="fill_parent" 
android:layout_height="fill_parent" 
android:background="@drawable/bckimageviw" > 
<ImageView 
    android:id="@+id/ColPhoto" 
    android:layout_width="0dp" 
    android:layout_height="0dp"/> 

<TextView 
    android:id="@+id/ColName" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:text="Name" /> 
</LinearLayout> 
1

하나의 LinearLayout 요소를 다른 LinearLayout에 추가하는 이유는 잘 모르겠습니다. 그리드 항목을 올바른 위치에 놓아야하는 경우 RelativeLayout을 대신 사용하고 싶습니다. `

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:orientation="horizontal" 
    android:layout_width="fill_parent" 
    android:layout_height="fill_parent" 
    > 
    <ImageView 
     android:id="@+id/ColPhoto" 
     android:layout_width="0dp" 
     android:layout_height="0dp" 
     /> 
    <TextView android:id="@+id/ColName" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:layout_below="@id/ColPhoto" 
     android:text="Name" 
     /> 
</RelativeLayout> 

`

관련 문제