android TextView EditTextView一些技巧使用 (视图代码布局)
android TextView 是最常用的控件
可以用作普通的顯示,還可以用作有顯示文字的按鈕,用作有顯示圖片的圖文組合
1、 圖文組合
xml 中:
<TextView
? ? ? ? android:id="@+id/txt_back"
? ? ? ? android:layout_width="wrap_content"
? ? ? ? android:layout_height="match_parent"
? ? ? ? android:layout_centerVertical="true"
? ? ? ? android:paddingLeft="@dimen/margin_padding_ten"
? ? ? ? android:paddingRight="@dimen/margin_padding_ten"
? ? ? ? android:drawableLeft="@drawable/user_btn_return"
? ? ? ? />
代碼中:
// TextView 左側(cè)顯示圖標(biāo)
Drawable drawable = getResources().getDrawable(R.drawable.skin_back);
// / 這一步必須要做,否則不會(huì)顯示.
drawable.setBounds(0, 0, drawable.getMinimumWidth(),drawable.getMinimumHeight());
backTextView.setCompoundDrawables(drawable,null,null,null);
2、RelativeLayout ?代碼布局居中
android.widget.RelativeLayout.LayoutParams lp = (LayoutParams) view.getLayoutParams();
lp.width = width;
lp.height = height;
lp.addRule(RelativeLayout.CENTER_IN_PARENT, RelativeLayout.TRUE); ?//居中
view.requestLayout();
3、TextView文字垂直靠左居中,
設(shè)置android:gravity="center_vertical|left"。
4、EditTextView 字?jǐn)?shù)限制
最簡(jiǎn)單的方式,如限制8個(gè)字符長(zhǎng)度
android:maxLength="8"
其它方式:http://blog.csdn.net/oliver102/article/details/10167637
5、TextView上下空隙
在安卓文檔中發(fā)現(xiàn)一個(gè)TextView屬性:
android:includeFontPadding????? 為上標(biāo)和下標(biāo)留出足夠的空間,以取代字體上下標(biāo).默認(rèn)為真.
原來是TextView默認(rèn)留下了上下的padding,是為了顯示上標(biāo)和下標(biāo)。
于是設(shè)置:android:includeFontPadding="false",問題解決
http://www.tuicool.com/articles/7vemI3u6、屬性限制字?jǐn)?shù)
android:maxLength="16"
不管是中文還是英文限制的單元都是16個(gè)轉(zhuǎn)載于:https://www.cnblogs.com/sucerli/p/4358419.html
總結(jié)
以上是生活随笔為你收集整理的android TextView EditTextView一些技巧使用 (视图代码布局)的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: SQL Server 影响dbcc ch
- 下一篇: hdu 1050 Moving Tabl