【问题标题】:How to make drawable height depends of the textview's text height?如何使可绘制高度取决于文本视图的文本高度?
【发布时间】:2017-07-02 00:22:18
【问题描述】:

我需要在我的文本视图中添加一个可绘制对象,并使其与文本具有相同的高度。

我的 xml:

...<LinearLayout
        android:id="@+id/line6"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_below="@+id/tableLayoutId">

        <TextView
            android:id="@+id/label10"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:paddingEnd="2dp"
            android:paddingRight="2dp"
            android:drawableRight="@drawable/greenarrowup"
            android:drawableEnd="@drawable/greenarrowup"
            /> ...

我得到了什么:

我想要什么:

我尝试使用 imageView 来获得所需的结果,但没有成功,有人可以帮助我吗?
谢谢。

【问题讨论】:

标签: android


【解决方案1】:

您应该设置线性布局的水平方向并像这样使用图像视图:

<LinearLayout
        android:id="@+id/line6"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:orientation="horizontal"
        android:layout_below="@+id/tableLayoutId">

        <TextView
            android:id="@+id/label10"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:paddingEnd="2dp"
            android:paddingRight="2dp"
            /> 

        <ImageView
        android:id="@+id/image"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        app:srcCompat="@drawable/greenarrowup" />


        </LinearLayout>

【讨论】:

    【解决方案2】:

    在textview上添加一定的高度并将重力设置为垂直居中

    【讨论】:

    • 感谢您的回答,但这不是我需要的。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2015-01-10
    • 2020-05-09
    • 2013-11-21
    • 1970-01-01
    • 2014-07-17
    • 2012-08-06
    • 1970-01-01
    相关资源
    最近更新 更多