【问题标题】:Styled gridview with border android带边框的样式化gridview android
【发布时间】:2012-08-17 18:21:36
【问题描述】:

我正在创建一个画廊类型的应用程序。我已经启动并运行了所有图片从手机加载并显示在网格视图中的基础知识。我希望 gridview 中的每个图像都有一个边框,可能是白色的,以便它们从黑色背景中脱颖而出。我想实现新 Instagram 使用的类似 gridview 的东西,但可能没有那么先进,周围有阴影。我已经搜索了网络,但我没有找到任何东西。 谢谢!

【问题讨论】:

标签: android gridview styles


【解决方案1】:

在drawable文件夹中创建一个名为stroke.xml的xml文件,

<shape xmlns:android="http://schemas.android.com/apk/res/android" android:shape="rectangle" >
   <solid android:color="#ffffff" />
   <stroke android:width="1dip" android:color="#4fa5d5"/>
</shape>

并将您在 GridView 中使用的 ImageView 的背景设置为该 xml 文件。

编辑:如果您希望在单击 GridView 项时看到橙色或蓝色,则必须按如下方式指定 ImageView 的属性..

<ImageView
        android:id="@+id/ivHighThumbnail"
        android:layout_width="80dip"
        android:layout_height="80dip"
        android:background="@drawable/stroke" 
        android:scaleType="fitXY"
        android:layout_margin="10dip" />

这里请注意属性

android:scaleType="fitXY"
android:layout_margin="10dip" 

这就是让您的项目感觉像是被点击并突出显示的原因。

在 stroke.xml 文件中也包含这个 xml 部分

<padding
        android:bottom="2dp"
        android:left="2dp"
        android:right="2dp"
        android:top="2dp" />

为了更好看的结果...

【讨论】:

  • 太棒了,正是我需要的。非常感谢!!简单易行。
  • 工作完美,但这样我在选择时会丢失所选样式。选择时如何使其显示为已选中?也许只是改变边框颜色或类似的东西。谢谢。
  • 您的意思是您在选择项目时没有看到橙色或蓝色的高亮颜色?
  • 是的。我一直在尝试解决这个问题,但我还没有找到解决方案。
猜你喜欢
  • 1970-01-01
  • 2022-01-26
  • 1970-01-01
  • 2015-07-29
  • 2011-08-15
  • 1970-01-01
  • 1970-01-01
  • 2018-05-08
  • 1970-01-01
相关资源
最近更新 更多