如何设置 android:drawable 到左侧和顶部?

sha*_* gh 2 android drawable

我只是想将图标设置到我的TextView. 这是我的代码和输出分别:

<TextView
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:text="@string/Content"
    android:drawableLeft="@drawable/icon" />
Run Code Online (Sandbox Code Playgroud)

输出:

输出

但我想将我的图标设置为顶部和左侧,如下所示:

在此输入图像描述

Dee*_*ana 5

为此,您必须像这样使用单独的 imageView,并在 textview 字段中添加一行代码 android:layout_toRightOf="@+id/imageView": 为了更好地理解,请参阅以下代码:

<RelativeLayout
    android:layout_width="match_parent"
    android:layout_height="wrap_content">
    <ImageView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:id="@+id/imageView"
        android:background="@mipmap/ic_launcher"
        />
    <TextView
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
      android:layout_toRightOf="@+id/imageView"
        android:text="this si fodfjkhsdhaffjsdfasdfjhsdfhjsdhfjhsdfhsdhfhdsjfhsdjhfjhdsfhsdhfjhsdjhfjsdhfjhsdjfhjsdhfjhsdjfhjdshfsdjhfjsdhfsdkjhfjsdhfjhsdjfhjsdhjfhsdjhfjsdhfjhjsdhfjsdhjfhsdjf"
        />

</RelativeLayout>
Run Code Online (Sandbox Code Playgroud)