在我的新 android 应用程序中,我需要使用 .9.png 之类的东西为 imageview
提供边框。
边框大小应该根据我给 imageview
的图像而改变,如果可能的话,我需要给 imageview
一个背景图像,因为我将要将透明的 png 图像应用于 imageview
。
我应该为此创建一个新的自定义 View 吗?
最佳答案
我认为您应该创建一个自定义 View 。做一个以背景为边框的 LinearLayout,并让 ImageView 在 LinearLayout 内居中。使用 9-patch 获得正确的拉伸(stretch)并创建内容区域以便显示边框(在 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)。您可以像内容区域一样进行拉伸(stretch)。
关于android - 如何在 Android 中为 ImageView 添加边框?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13971874/