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 左側顯示圖標
Drawable drawable = getResources().getDrawable(R.drawable.skin_back);
// / 這一步必須要做,否則不會顯示.
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文字垂直靠左居中,
設置android:gravity="center_vertical|left"。
4、EditTextView 字數限制
最簡單的方式,如限制8個字符長度
android:maxLength="8"
其它方式:http://blog.csdn.net/oliver102/article/details/10167637
5、TextView上下空隙
在安卓文檔中發現一個TextView屬性:
android:includeFontPadding????? 為上標和下標留出足夠的空間,以取代字體上下標.默認為真.
原來是TextView默認留下了上下的padding,是為了顯示上標和下標。
于是設置:android:includeFontPadding="false",問題解決
http://www.tuicool.com/articles/7vemI3u6、屬性限制字數
android:maxLength="16"
不管是中文還是英文限制的單元都是16個轉載于:https://www.cnblogs.com/sucerli/p/4358419.html
總結
以上是生活随笔為你收集整理的android TextView EditTextView一些技巧使用 (视图代码布局)的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: SQL Server 影响dbcc ch
- 下一篇: hdu 1050 Moving Tabl