Android 如何在不通过文本的情况下获得环绕文本视图的行?
我计划实现以下目标:Android 如何在不通过文本的情况下获得环绕文本视图的行?,android,android-layout,android-fragments,textview,android-relativelayout,Android,Android Layout,Android Fragments,Textview,Android Relativelayout,我计划实现以下目标: ---------------Text--------------- 其中“----”实际上是一条线(可能是视图线?或分隔线) 更准确地说,这是我努力实现的一个例子: 我想知道如何在我的文本视图中实现这一点。以下是我的布局: <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="wrap_content" and
---------------Text---------------
其中“----”实际上是一条线(可能是视图线?或分隔线)
更准确地说,这是我努力实现的一个例子:
我想知道如何在我的文本视图中实现这一点。以下是我的布局:
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="wrap_content"
android:layout_height="wrap_content">
<TextView
android:id="@+id/mydate"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center"
android:textColor="@android:color/darker_gray"
android:textSize="18sp"/>
</RelativeLayout>
您可以通过创建一条全宽的单行线,然后将文本视图放在上面来实现这一点。如果您为TextView提供与父对象背景相同的背景色,并为TextView提供一些左右填充,它将与您的示例类似 您可以将其用于行(res/drawable目录中的line.xml):
然后使用此布局:
<FrameLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
>
<ImageView
android:layout_width="match_parent"
android:layout_height="10dp"
android:src="@drawable/line"
android:layout_gravity="center"
/>
<TextView
android:id="@+id/mydate"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:paddingLeft="10dp"
android:paddingRight="10dp"
android:background="@android:color/white"
android:textColor="@android:color/darker_gray"
/>
</FrameLayout>
该行穿过文本。我希望能在没有划破的情况下将其环绕在文本中。我的缺点是,缺少背景,效果很好,谢谢!
<FrameLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
>
<ImageView
android:layout_width="match_parent"
android:layout_height="10dp"
android:src="@drawable/line"
android:layout_gravity="center"
/>
<TextView
android:id="@+id/mydate"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:paddingLeft="10dp"
android:paddingRight="10dp"
android:background="@android:color/white"
android:textColor="@android:color/darker_gray"
/>
</FrameLayout>