如何设置宽度等于Android上的另一个小部件 [英] how to set width which is equal to another widget on android

查看:77
本文介绍了如何设置宽度等于Android上的另一个小部件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要在文本字段下方绘制一条水平线,以使该行的宽度等于文本宽度(而不是全屏宽度).

I need to draw a horizontal line below a text field such that the width of the line equals the text width (not the width of the full screen).

在我的应用中,我在视图(水平线)下方有一个textview. 线条视图的宽度应等于文本视图的宽度. 我尝试了android:layout_width ="wrap_content"和"match_parent",但这不能解决问题.

In my app I have a textview below a view(Horizontal line). The width of the line view should be equal to the width of the textview. I tried android:layout_width="wrap_content" and "match_parent", which does not solve the problem.

这是xml编码示例:

         ......
        <TextView
            android:id="@+id/textView1"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_alignParentTop="true"
            android:layout_centerHorizontal="true"
            android:layout_marginTop="28dp"
            android:text="PopUpWindow"
            android:textAppearance="?android:attr/textAppearanceLarge" />


            <View
                android:id="@+id/separator"
                android:layout_width="wrap_content"
                android:layout_height="0.3dp"
                android:layout_below="@+id/textView1"
                android:background="#ffffff" />
             ......

屏幕图像为:

请帮助我.

推荐答案

如果使用RelativeLayout,则可以使用align-属性:

If you use a RelativeLayout you can use the align-attributes:

<View
    android:id="@+id/separator"
    android:layout_width="0dp"
    android:layout_height="0.3dp"
    android:layout_below="@+id/textView1"
    android:layout_alignLeft="@+id/textView1"
    android:layout_alignRight="@+id/textView1"
    android:background="#ffffff" />

这篇关于如何设置宽度等于Android上的另一个小部件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆