开发者

Creating a 'Pretty' GridView

Now that the backend of my app/server are pretty much complete it's time to move on and fix my gridview. I was developing on my HTC EVO and doing some bad things (ie setting heights and widths to actual pixel sizes).

Right now I have an image on top of a textview in each gridview cell.

Here is my XML for a cell:

<RelativeLayout  xmlns:android="http://schemas.android.com/apk/res/android"            
  android:id = "@+id/single_item_id"  
  android:layout_width="100dp"
  android:layout_height="140px"      
  android:orientation="vertical"
  > 
  <ImageView
  android:id = "@+id/album_image"
  android:adjustViewBounds="true"
  android:layout_gravity="center_horizontal"
  android:layout_width="90dp"
  android:layout_height="80px"
  />

  <TextView 
  android:text="TextView" 
  android:id="@+id/textView1" 
  android:layout_width="wrap_content" 
  android:layout_height="60px"
  android:textSize="12sp"
  android:gravity="center" 
  android:layout_gravity="center_horizontal"
  android:layout_below="@id/album_image">
  </TextView>

Here is my gridview xml:

<GridView
  android:id="@+id/gridview"
      android:layout_width="wrap_content" 
  android:layout_height="fill_parent"
  android:numColumns="auto_fit"
  android:verticalSpacing="10dp"
  andro开发者_Go百科id:horizontalSpacing="10dp"
  android:columnWidth="90dp"
  android:stretchMode="columnWidth"
  android:gravity="center"
  android:layout_below="@id/firstDivider"></GridView>

My Issues...

I know I'm not doing things very well but I need some pointers (for some reason this is the hardest for me). In code this is what I'm doing:

v.setLayoutParams(new GridView.LayoutParams(width / 3,height / 6));

where width/height is the device width/height. This makes things a little better...

here iv is my image view:

iv.setPadding(8, 0, 8, 0);
iv.setScaleType(ImageView.ScaleType.CENTER_CROP);

still the images just don't look right :(

In addition to all of that the text in my textview is never centered ! These are the things that pop out to me as being the biggest issues right now.

I do realize that my question is rather vague but any advice would be great.


I looks like you are modifing the image view (sizes) on top of setting them in the layout. What I think you need to do is in the Adapter.getView(...) just inflate the layout and set the layoutParams of the the layout not the image.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜