1、水平布局,一边文字,一边图片
这种情况,如果利用比例,很有可能会有图片显示不完整的问题,所以最好使用如下View占位的方法:
<LinearLayout
android:layout_width="match_parent"
android:layout_height="60dp"
android:padding="20dp">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="这是左边文字"/>
<View
android:layout_width="0dp"
android:layout_weight="1"
android:layout_height="match_parent"/>
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@drawable/btn_check"/>
</LinearLayout>
2、水平布局,两边都是文字,文字长度一边确定,一边不确定
这种情况最好也不要使用比例,主要是因为左右比例自己也很难确定。这时常用的是如下方式:
<LinearLayout
android:layout_width="match_parent"
android:layout_height="60dp"
android:padding="20dp">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="这是左边文字"/>
<TextView
android:layout_width="0dp"
android:layout_weight="1"
android:gravity="end"
android:layout_height="wrap_content"
android:text="这是右边不确定长度文字"/>
</LinearLayout>
意思就是除了左边文字所占的宽度位置,其余的宽度位置均为右边Text所有。
3、文字四周有图片
这种情况就不用把文字和图片单独给个控件了,一个TextView就能解决了:
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="这是文字"
android:drawableBottom="@drawable/btn_check"
android:drawablePadding="10dp"/>
●其中android:drawableBottom属性是指图片相对于文字的位置在在底部,同样drawableLeft表示图片在文字左边,等等。
●其中android:drawablePadding属性是指图片与文字的距离。
4、TextView实现竖排文字
实现竖排文字使用一个TextView的属性就可以了:
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textSize="20sp"
android:text="这是竖排文字"
android:ems="1"
android:lineSpacingExtra="10dp" />
●其中android:ems=“1”属性就是指每行一个文字
●其中android:lineSpacingExtra属性是指文字之间的行间距