Android Button1.图文混排
来源:互联网 发布:linux黑客系统 编辑:程序博客网 时间:2024/05/21 09:23
1.在布局文件中设置图文混排
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent" android:layout_height="match_parent" android:orientation="vertical" tools:context="com.example.androidbutton.MainActivity" > <LinearLayout android:layout_width="match_parent" android:layout_height="wrap_content" android:orientation="vertical" > <Button android:layout_width="wrap_content" android:layout_height="wrap_content" android:drawableTop="@drawable/star" android:text="button1" /> <Button android:layout_width="wrap_content" android:layout_height="wrap_content" android:drawablePadding="30dp" android:drawableRight="@drawable/star" android:text="button2" /> <Button android:layout_width="wrap_content" android:layout_height="wrap_content" android:drawablePadding="50dp" android:drawableTop="@drawable/star" android:text="button3" /> <Button android:layout_width="wrap_content" android:layout_height="wrap_content" android:drawableLeft="@drawable/star" android:drawableTop="@drawable/star" android:text="button4" /> </LinearLayout> <Button android:id="@+id/button" android:layout_width="200dp" android:layout_height="200dp" android:layout_margin="0dp" android:text="kk" /></LinearLayout>
2.在java代码中设置图文混排
public class MainActivity extends ActionBarActivity {@Overrideprotected void onCreate(Bundle savedInstanceState) {super.onCreate(savedInstanceState);setContentView(R.layout.activity_main);Button button = (Button) findViewById(R.id.button);SpannableString spannableStringLeft = new SpannableString("left");Bitmap bitmapLeft = BitmapFactory.decodeResource(getResources(),R.drawable.image_left);ImageSpan imageSpanLeft = new ImageSpan(bitmapLeft,DynamicDrawableSpan.ALIGN_BOTTOM);spannableStringLeft.setSpan(imageSpanLeft, 0, 4,Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);SpannableString spannableStringRight = new SpannableString("right");Bitmap bitmapRight = BitmapFactory.decodeResource(getResources(),R.drawable.image_right);ImageSpan imageSpanRight = new ImageSpan(bitmapRight);spannableStringRight.setSpan(imageSpanRight, 0, 5,Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);button.append(spannableStringLeft);button.append("我的按钮...");button.append(spannableStringRight);}}
1 0
- Android Button1.图文混排
- android图文混排
- Android图文混排
- Android 图文混排
- android图文混排
- Android图文混排
- Android图文混排
- Android 图文混排
- android图文混排
- Android ListView - 图文混排
- android 显示图文混排
- android TextView图文混排
- android TextView图文混排
- [Android]listview图文混排
- android edittext图文混排
- Android/Html图文混排
- Android图文混排
- android 图文混排 显示 与 图文混排输入
- 快速使用Python2.7和Django1.9
- c# - yield
- 2016蓝桥杯假期任务之《三部排序》
- c++你不知道的用法之foreach篇
- PLC远程通讯功能集锦(互联网、局域网)(PLC远程监控,PLC远程监视,PLC手机监控)
- Android Button1.图文混排
- Fragment的生命周期
- android 内存优化分析
- jQuery事件之中有其他事件,return 和局部变量无效
- ios 键盘遮挡,监听键盘调整view的frame
- 如何用不同的方式来处理安卓的权限管理?
- Usb Audio Device Descriptor(6) Standard AS Interface Descriptor
- Android开发之VideoView
- MT7620A SD卡初始化失败