Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/image/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
带有图像和文本的Android ImageButton_Android_Image_Text_Button_Imagebutton - Fatal编程技术网

带有图像和文本的Android ImageButton

带有图像和文本的Android ImageButton,android,image,text,button,imagebutton,Android,Image,Text,Button,Imagebutton,我想有一个按钮,上面有一个图像,底部有一些文字。图像和文本都是在运行时决定的,因此我希望能够为每个按钮组合ImageButton的setImageBitmap和Button的setText 有什么想法吗 谢谢 克里斯我认为没有一个简单的方法可以做到这一点 我会创建一个。我终于找到了我想要的: SetCompoundDrawableSwithinInstructBounds允许我为按钮指定位图/可绘制,同时允许我使用setText。例如:要在按钮顶部设置位图图像,请执行以下操作 setCompou

我想有一个按钮,上面有一个图像,底部有一些文字。图像和文本都是在运行时决定的,因此我希望能够为每个按钮组合ImageButton的setImageBitmap和Button的setText

有什么想法吗

谢谢
克里斯

我认为没有一个简单的方法可以做到这一点


我会创建一个。我终于找到了我想要的:


SetCompoundDrawableSwithinInstructBounds允许我为按钮指定位图/可绘制,同时允许我使用setText。

例如:要在按钮顶部设置位图图像,请执行以下操作


setCompoundDrawableSwithinInstincBounds(null,新的BitmapDrawable(bitmapimage),null,null)

将图像按钮和文本视图代码环绕在。。。。覆盖图像按钮背景上的文本。i、 e:

 <FrameLayout
        android:layout_width="wrap_content"
        android:layout_height="wrap_content" >

        <ImageButton
            android:id="@+id/imageButton1"
            android:layout_width="100dp"
            android:layout_height="100dp"
            android:layout_alignParentLeft="true"
            android:layout_alignParentTop="true"
            android:layout_marginLeft="69dp"
            android:layout_marginTop="96dp"
            android:background="@drawable/icon"
            android:scaleType="fitXY" />

        <TextView
            android:id="@+id/text"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_gravity="center"
            android:text="Droid"
            android:textColor="#ff0000"
            android:textSize="24dip" >
        </TextView>
    </FrameLayout>


Duplicate:我在提问之前看了那个问题,但我不能同意那里指定的答案,因为,1。我无法将图像设置为背景,我希望图像在顶部,文本在底部,而不是图像上的文本。2.我需要以编程的方式进行设置,不能使用XML,然后在另一个副本中查看我的答案:它完全可以通过XML定义layout@ognian:您可以使用XML布局定义自定义组件。是,但是我想说的是,没有必要创建视图的另一个子类,只需要有一个包含图像和文本的按钮,这是一个包含文本和图像的按钮,而不是ImageButton,所以这还不是原始问题的解决方案,而是一个解决方法。