创造一个“漂亮的”网格视图
现在我的应用程序/服务器的后端已基本完成,是时候继续修复我的网格视图了。我正在我的 HTC EVO 上进行开发并做了一些不好的事情(即将高度和宽度设置为实际像素大小)。
现在,我在每个网格视图单元格的文本视图顶部都有一个图像。
这是我的单元格 XML:
<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>
这是我的 gridview xml:
<GridView
android:id="@+id/gridview"
android:layout_width="wrap_content"
android:layout_height="fill_parent"
android:numColumns="auto_fit"
android:verticalSpacing="10dp"
android:horizontalSpacing="10dp"
android:columnWidth="90dp"
android:stretchMode="columnWidth"
android:gravity="center"
android:layout_below="@id/firstDivider"></GridView>
我的问题...
我知道我做得不太好,但我需要一些指导(出于某种原因,这对我来说是最难的)。在代码中,这就是我正在做的:
v.setLayoutParams(new GridView.LayoutParams(width / 3,height / 6));
其中宽度/高度是设备宽度/高度。这让事情变得更好了...
这里 iv 是我的图像视图:
iv.setPadding(8, 0, 8, 0);
iv.setScaleType(ImageView.ScaleType.CENTER_CROP);
图像仍然看起来不正确:(
除此之外,我的文本视图中的文本从未居中!这些是弹出的内容我现在是最大的问题,
我确实意识到我的问题相当模糊,但任何建议都会很好。
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"
android: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.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我看起来您正在修改图像视图(尺寸),而不是在布局中设置它们。我认为您需要做的是在 Adapter.getView(...) 中只需膨胀布局并设置布局的布局参数而不是图像。
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.