我是 android 的新手,我必须实现一个看起来像这样的 View :
-------------Some Text----------------------
我知道我可以使用 View
在我的 xml 中使用如下代码绘制一条线:
<View
android:layout_width="100dp"
android:layout_height="1dp"
android:background="#00ff00" />
这将最终绘制:
-----------------------
但在此之后我希望放置文本并再次绘制线的另一端。
我试过了,但我得到了这样的结果:
----------------------
text
当我在 View
代码之后添加一些 TextView
时。
这有可能实现我的目标吗?
提前致谢。
最佳答案
也许这会帮助你得到你想要的。给 View 赋予权重是关键..
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:gravity="center"
android:orientation="horizontal" >
<View
android:layout_width="fill_parent"
android:layout_height="1dp"
android:layout_weight="1"
android:background="#00ff00" />
<TextView
android:id="@+id/textView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/hello_world" />
<View
android:layout_width="fill_parent"
android:layout_height="1dp"
android:layout_gravity="center"
android:layout_weight="1"
android:background="#00ff00" />
</LinearLayout>
关于android - 如何在android中心画一条线和一些文本?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15133242/