Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/206.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Android 带方向箭头的背景_Android_Background_Android View_Layer List - Fatal编程技术网

Android 带方向箭头的背景

Android 带方向箭头的背景,android,background,android-view,layer-list,Android,Background,Android View,Layer List,我有一个关于如何在视图上获得所需背景视图的快速问题。我想要的是一个指向某个方向的方向箭头,作为文本视图背景上的覆盖 例如(美丽的MS绘画技巧) 我已经尝试过使用一个图层列表,但在这种情况下,由于屏幕大小的变化或内容高度的波动,该列表不起作用。除了使用9patch之外,还有其他可行的方法吗。我一直害怕研究9个补丁,因为我完全不懂图形设计。实际上,这可以在图层列表中使用。就在我的头顶上,你可以这样做: <layer-list xmlns:android="http://schemas.and

我有一个关于如何在视图上获得所需背景视图的快速问题。我想要的是一个指向某个方向的方向箭头,作为文本视图背景上的覆盖

例如(美丽的MS绘画技巧)


我已经尝试过使用一个图层列表,但在这种情况下,由于屏幕大小的变化或内容高度的波动,该列表不起作用。除了使用9patch之外,还有其他可行的方法吗。我一直害怕研究9个补丁,因为我完全不懂图形设计。

实际上,这可以在图层列表中使用。就在我的头顶上,你可以这样做:

<layer-list xmlns:android="http://schemas.android.com/apk/res/android" >

   <item android:left="10dp"> <!-- offset from the left -->
       <bitmap android:src="@drawable/arrow_icon"/>
   </item>

   <item android:top="5dp"> <!-- replace with the hight of your arrow -->
       <shape> <solid android:src="#FFFFFF"/> </shape>
   </item>

</layer-list>
<TextView
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:background="@drawable/with_arrow"
    android:paddingTop="5dp"/> <!-- should be AT LEAST the height of your arrow, might want to increase it a bit though -->
例如,如果您将其设置为textview的背景,则它应使用内容对其进行拉伸

另一方面,您应该真正研究9-patching。其实没那么复杂
请参见此处:

类似于此附加文件的内容会有所帮助吗?在绘制中创建,然后用于绘制拉伸线

你可能已经看过好几年的文档了


箭头是否需要位于不同的位置,或者从左侧的偏移量是否总是相同的?实际上是向上的。我认为图层列表不起作用的原因是,例如,您将其作为文本视图的背景,而您的箭头是30px x x 30px(xhdpi),a)无法将其推到背景的顶部(您可以在位图上尝试android:gravity=“top | left”,结果与预期不符)现在你要设置背景的偏移,现在你的文本视图将在空白箭头空间和背景空间之间。我想我只需要引用9个补丁。是的,我应该提到,你需要在顶部添加更多的填充物来与箭头下面的文本对齐。如果你至少添加安卓:PADIN。gTop=“5dp”文本应向右对齐添加了一个清晰的示例刚刚尝试过,是的,这正是我想要的,现在我只需找到一种方法使其自行收缩箭头并将其向左移动更多。谢谢,尽管解决方案是使用9patch