【发布时间】:2012-12-20 12:06:38
【问题描述】:
在我的新 android 应用程序中,我需要使用 .9.png 之类的东西为 imageview 提供边框。
边框大小应该根据我提供给imageview 的图像而改变,如果可能的话,我需要给imageview 提供背景图像,因为我将向imageview 应用透明的png 图像。
我应该为此创建一个新的自定义视图吗?
【问题讨论】:
标签: android background imageview
在我的新 android 应用程序中,我需要使用 .9.png 之类的东西为 imageview 提供边框。
边框大小应该根据我提供给imageview 的图像而改变,如果可能的话,我需要给imageview 提供背景图像,因为我将向imageview 应用透明的png 图像。
我应该为此创建一个新的自定义视图吗?
【问题讨论】:
标签: android background imageview
我认为您应该创建一个自定义视图。做一个以背景为边框的 LinearLayout,并使 ImageView 在 LinearLayout 内居中。使用 9-patch 获得正确的拉伸并创建内容区域以便显示边框(在 android SDK/Tools 中使用 draw9patch)。
例子:
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="@drawable/border">
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
/>
</LinearLayout>
然后 9-patch 你的边框(在这个例子中是border.9.png)。您可以与内容区域进行相同的拉伸。
【讨论】: