Android 巧妙实现图片和文字布局

  • Post author:
  • Post category:其他


之前写过一个博客是关于实现图片和文字左右或者上下布局的方法,

下面是博客的主要内容:

布局文件很简单,用来展示RadioButton的使用方法。

 1 <?xml version="1.0" encoding="utf-8"?>
 2 <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
 3     android:layout_width="match_parent"
 4     android:layout_height="match_parent"
 5     android:orientation="vertical" >
 6 
 7     <RadioButton
 8         android:layout_width="wrap_content"
 9         android:layout_height="wrap_content"
10         android:layout_centerInParent="true"
11         android:button="@null"
12         android:drawableTop="@drawable/ic_launcher"
13         android:text="Test Button" />
14 
15 </RelativeLayout>

效果图如下

今天偶然的时候发现不只是RadioButton有

android:drawableTop这个属性,好多的控件都有这个属性,像TextView、ChexkBox等等,而且还可以通过设置drawablepadding来设置图片和文字的距离。
这样就可以省的写LinearLayout或者RelativeLayout来实现这种布局方式,更加有效的实现布局。

转载于:https://www.cnblogs.com/mc-ksuu/p/4972826.html