日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

android TextView EditTextView一些技巧使用 (视图代码布局)

發布時間:2024/4/14 编程问答 25 豆豆
生活随笔 收集整理的這篇文章主要介紹了 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/7vemI3u


6、屬性限制字數

android:maxLength="16"

不管是中文還是英文限制的單元都是16個



轉載于:https://www.cnblogs.com/sucerli/p/4358419.html

總結

以上是生活随笔為你收集整理的android TextView EditTextView一些技巧使用 (视图代码布局)的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。