Android一些常用設置

1、指定TextView一行顯示幾個字符,多餘的省略號

        android:singleLine="true"
        android:ellipsize="end"
        android:maxEms="4"

 

2、透明度轉換


100% —FF–> ,95% — F2–> ,90% — E6–> ,85% — D9–> ,80% — CC–> ,75% — BF–> ,70% — B3–>,65% — A6–> ,60% — 99–> ,55% — 8C–> ,50% — 80–> ,45% — 73–> ,40% — 66–> ,35% — 59–> ,30% — 4D–> ,25% — 40–> ,20% — 33–> ,15% — 26–> ,10% — 1A–> ,5% — 0D–> ,0% — 00–>

 

3、shape寫背景selector

<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
    <item android:state_checked="true">
        <layer-list xmlns:android="http://schemas.android.com/apk/res/android">
            <item>
                <shape>
                    <solid android:color="#FFFFFF" />
                </shape>
            </item>
            <item android:top="@dimen/y63"
                android:bottom="@dimen/y17"
                android:left="@dimen/x88"
                android:right="@dimen/x88">
                <shape android:shape="rectangle">
                    <solid android:color="#00a65f" />
                    <size android:height="@dimen/y4" android:width="@dimen/x40"/>
                </shape>
            </item>
        </layer-list>
    </item>
    <item>
        <shape xmlns:android="http://schemas.android.com/apk/res/android">
            <solid android:color="#ffffff" />
        </shape>
    </item>
</selector>

4、指定TextView顯示2行,多餘的省略號

android:lines="2"
android:ellipsize="end"

5、ScrollView中嵌套RecyclerView顯示不全

val layoutManager: LinearLayoutManager = object : LinearLayoutManager(holder.getContext()) {
   override fun generateDefaultLayoutParams(): RecyclerView.LayoutParams {
      return RecyclerView.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT,
                        ViewGroup.LayoutParams.WRAP_CONTENT)
   }
}
layoutManager.orientation = LinearLayoutManager.VERTICAL
re.layoutManager = layoutManager

6、TextView跑馬燈

重寫TextView的isFocused方法返回true

xml

 android:ellipsize="marquee"
 android:marqueeRepeatLimit="marquee_forever"
 android:singleLine="true"

7、TextView內容顯示不全可以上下滑動

xml
android:scrollbars="vertical"
code
tvContent.movementMethod = ScrollingMovementMethod.getInstance()

8、TextView自動識別郵箱、電話、鏈接,點擊可跳轉

android:autoLink="email|phone|web"

9、TextView畫虛線

 

需要在TextView的xml中添加,設置背景使用shape.xml

android:layerType="software"
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
    android:shape="line" >
    <stroke
        android:dashGap="@dimen/x6"
        android:dashWidth="@dimen/x6"
        android:width="@dimen/x2"
        android:color="#D8D8D8" />
    <!-- 虛線的高度 -->
    <size android:height="@dimen/y2" />
</shape>

10、TextView去掉默認的邊上空白間隙

android:includeFontPadding="false"

 

 

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章