Android在按钮中的文本后立即设置图像

时间:2018-03-20 01:47:05

标签: android xamarin xamarin.android

如何在Xamarin.Android中的文本(文本右侧)之后立即设置图像。

我尝试过以下代码:

Control.SetCompoundDrawablesRelativeWithIntrinsicBounds(null, null, drawable , null);

这会将图像设置在按钮的最右侧,而不是在文本

之后

1 个答案:

答案 0 :(得分:0)

SetCompoundDrawable始终将图像设置为Drawables'内在界限。因此它将出现在视图的左侧,顶部,右侧和底部。

因此,如果您需要它出现在文本旁边,那么您必须创建自己的视图,看起来像一个按钮。

前:

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
  android:layout_width="fill_parent"
  android:layout_height="wrap_content"
  android:padding="5dip" >


<ImageView
android:id="@+id/imgIcon"
android:background="@drawable/image_bg"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:scaleType="fitXY"/>

<TextView
    android:id="@+id/txtTitle"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_toRightOf="@+id/imgIcon"
    android:typeface="sans"
    android:layout_marginLeft="3dp" />

</RelativeLayout